Andy Freeman <anamax@earthlink.net> wrote:
+---------------
| hs@paradise.nirvananet (Hartmann Schaffer) wrote:
| > it's been a while, but my understanding of synchronization points was
| > that after a sybchrobization point side effects in the preceeding
| > expression had to have an effect on subsequent calculations. if
| > the compiler can determine that a side effect result is redundant, it
| > can discard them and the problem becomes mute
|
| That's a huge "if". How does a compiler know about side effects on
| other processes via memory accesses?
+---------------
You have to tell it. That's what the ANSI C "volatile" attribute is
all about. It tells the compiler that it *can't* depend on a location
being affected only by what it can prove about "local" code. For example,
consider "busy-waitng" on a flag that can be changed by an interrupt
routine:
extern volatile done_flag;
...
while (!done_flag)
; /*wait*/
Without the "volatile" declaration, the compiler would be completely
justified in treating the above exactly the same as this:
if (!done_flag) /* only need to test once, since never assigned to */
for(;;)
;
which is an infinite loop if "done_flag" was false on entry.
-Rob
-----
Rob Warnock, 31-2-510 rpw3@sgi.com
SGI Network Engineering http://reality.sgi.com/rpw3/
1600 Amphitheatre Pkwy. Phone: 650-933-1673
Mountain View, CA 94043 PP-ASEL-IA