Atomic Operations (continuing on from Masking Interrupts?)
Doug Evans
devans@cygnus.com
Tue Jul 6 13:33:00 GMT 1999
From: David Williams <davidwilliams@ozemail.com.au>
Date: Tue, 6 Jul 1999 11:03:45 +1000
Thanks for the helpful suggestions. I have now implemented some in line
assembly with constraints etc. as suggested to ensure atomic operations.
This started me thinking...(very dangerous!). Some responses indicated that
others have experienced this 'problem' before. As GCC and support for M68K
have been around for quite some time I assume that a 'fix' in the compiler
is probably difficult.
Except that there's nothing to fix (as far as this goes).
Has anyone considered some sort of fix for this? Is it difficult? I would
offer my time to look at the problem, however I have not written any
compilers, nor modified any and even though I like a challenge I am not
sure that the time it would take to get up to speed is available to me.
excuses, excuses, excuses...
I would have thought that by specifying a variable to be 'volatile' then it
should be assumed that it could change at anytime. Therefore an atomic
operation should be used, if available on the micro concerned. Otherwise
the variable could change during a read,modify, write sequence causing a
conflict. Any thoughts on this?
`volatile' does not mean this. The C Standard makes no reference to
atomic operations (obviously, since not all machines have them).
[well, except for sig_atomic_t, but that's a separate issue].
The short answer is that references to volatile storage can't be
optimized away, the "object shall be evaluated strictly according to the rules
of the abstract machine", nothing more (the long answer I'll probably get
wrong ... :-).
Others can quote all of section 3.5.3 (ANSI numbering, don't have ISO numbering
handy) if they want to.
Thus, for example, in the following
volatile int a,b;
void
foo ()
{
a = a + 1;
a = a + 1;
b = 42;
b = 42;
}
the compiler can't replace this with
b = 42;
a = a + 2;
Take out the `volatile', and it can.
_______________________________________________
New CrossGCC FAQ: http://www.objsw.com/CrossGCC
_______________________________________________
To remove yourself from the crossgcc list, send
mail to crossgcc-request@cygnus.com with the
text 'unsubscribe' (without the quotes) in the
body of the message.
More information about the crossgcc
mailing list