This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Question on volatile functions and GCC


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]