Inter-thread communication

Started by
20 comments, last by Hodgman 9 years, 8 months ago



Regarding volatile, IMHO unless you're writing a device driver, the only place you should use volatile is inside the implementation of std::atomic (or similar reinvented wheel).
Even std::atomic shouldn't be using volatile. You really need hardware memory barriers for atomic operations, except in cases where the basic load and store instructions provide sufficient synchronization guarantees. You also need compiler hooks to ensure that the more lax operations are respected, including ubiquitous acquire-release semantics.
Advertisement

Regarding volatile, IMHO unless you're writing a device driver, the only place you should use volatile is inside the implementation of std::atomic (or similar reinvented wheel).

Even std::atomic shouldn't be using volatile. You really need hardware memory barriers for atomic operations, except in cases where the basic load and store instructions provide sufficient synchronization guarantees. You also need compiler hooks to ensure that the more lax operations are respected, including ubiquitous acquire-release semantics.
True - but for some reason MS decided that the Interlocked intrinsics (which act as runtime and compile-time memory fences) can only be passed volatile integers... :/
So you'll definitely see the keyword used on a Windows/MSVC implementation ;-)

This topic is closed to new replies.

Advertisement