Search code examples
c++multithreadingmutexmemory-barriersmemory-model

Does std::mutex create a fence?


If I lock a std::mutex will I always get a memory fence? I am unsure if it implies or enforces you to get the fence.

Update:

Found this reference following up on RMF's comments.

Multithreaded programming and memory visibility


Solution

  • Unlocking a mutex synchronizes with locking the mutex. I don't know what options the compiler has for the implementation, but you get the same effect of a fence.