Question on volatile functions and GCC
Ian Lance Taylor
iant@google.com
Tue Mar 5 14:35:00 GMT 2013
On Tue, Mar 5, 2013 at 1:58 AM, David Paterson <dnpaterson@gmail.com> wrote:
> On 5 March 2013 09:40, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
>
>> volatile is not for multithreading, you need proper synchronization
>> for interthread communication.
>
> Not always. For very simple, non-critical uses you can just use a
> volatile flag-type variable. Cheap and nasty, I agree, but useable.
If your code has a race condition before you add a volatile qualifier,
it will still have a race condition after you add the qualifier.
If you want a simple flag variable, don't use volatile; use
__atomic_load and __atomic_store.
Ian
More information about the Gcc-help
mailing list