by dragontamer · 8y ago · 0 comments
I'm going to guess you're a Java programmer. What you say is true in Java but not in C.
In C, volatile doesn't necessarily generate memory barriers. Volatile just means that the memory can't be stored in a register, the CPU will re-read the memory address each time. To generate memory barriers, you need to use the C11 atomics. A combination of "atomic_store" and "atomic_thread_fence" is needed. The C11 model has fences relative to a specific atomic operation.
See the newer header file #include<atomics.h> for more details.
Thanks to you and others for the clarification on C's (lack of) behaviour!