This is the mail archive of the
mailing list for the crossgcc project.
Re: Atomic Operations (continuing on from Masking Interrupts?)
- To: email@example.com
- Subject: Re: Atomic Operations (continuing on from Masking Interrupts?)
- From: Doug Evans <firstname.lastname@example.org>
- Date: Tue, 6 Jul 1999 10:57:14 -0700
- Reply-To: email@example.com
From: David Williams <firstname.lastname@example.org>
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;
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 email@example.com with the
text 'unsubscribe' (without the quotes) in the
body of the message.