On 9/11/11, Andrew MacLeod <amacl...@redhat.com> wrote: > On 09/09/2011 09:09 PM, Geert Bosch wrote: >> For the C++0x atomic types there are: >> >> void A::store(C desired, memory_order order = memory_order_seq_cst) >> volatile; >> void A::store(C desired, memory_order order = memory_order_seq_cst); >> >> where the first variant (with order = memory_order_relaxed) >> would allow fences to be omitted, while still preventing the compiler from >> reordering memory accesses, IIUC. > > I thought the volatile tags were actually for type correctness so the > compiler wouldn't complain when used on volatile objects.... Ie, you > can't call a non volatile method with a volatile object, or something > like that.
Volatile means the same thing with atomics that it does without the atomics, that an external agent may affect the value or that writes to the value may effect external agents. The C++ standards committee has anticipated optimizing atomic operations, and even eliminating them entirely when it eliminates entire threads. However, one cannot do that with volatile because you might fail to coordinate with the external agent. I think the most likely use of volatile atomics is in communicating between to processes sharing memory. Note, though, that such atomics may need to be lock-free and/or address-free. -- Lawrence Crowl