What are examples of memory barriers in C++?
I see C++11 mutexes lock is not void lock() volatile . How does the compiler know which functions are memory barriers and which are not? Are all functions barriers even if they are not volatile? What are some less known memory barriers and memory barriers everyone should know? The runtime library has to implement a mutex in a way so that the compiler knows! The language standard doesn't say anything about how to do this. Likely, it involves a call to some operating system service that works as a memory barrier. Or the compiler can have an extension, like void _ReadWriteBarrier(); The actual