[C++]Memory Ordering & Memory Barrier Notes
keywords: C++, Memory Ordering Notes
Documents
Memory ordering
Memory ordering
https://en.wikipedia.org/wiki/Memory_ordering
std::memory_order
https://en.cppreference.com/w/cpp/atomic/memory_order
Memory Ordering at Compile Time
https://preshing.com/20120625/memory-ordering-at-compile-time/
Memory Reordering Caught in the Act
https://preshing.com/20120515/memory-reordering-caught-in-the-act/
Concurrency: Atomic and volatile in C++11 memory model
https://stackoverflow.com/a/8833218/1645289
volatile
Single producer single consumer command queue
https://codereview.stackexchange.com/a/152338
Deprecation of _writeBarrier()
https://stackoverflow.com/a/60257744/1645289
C++ and the Perils of Double-Checked Locking
https://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf
Memory barrier (Memory fence)
Memory Reordering Caught in the Act
https://preshing.com/20120515/memory-reordering-caught-in-the-act/
_mm_sfence & _mm_mfence
https://stackoverflow.com/a/12850294/1645289
https://stackoverflow.com/a/50780314/1645289
Understanding c++11 memory fences
https://stackoverflow.com/questions/13632344/understanding-c11-memory-fences
Memory barrier
https://en.wikipedia.org/wiki/Memory_barrier
内存屏障
https://zh.wikipedia.org/wiki/%E5%86%85%E5%AD%98%E5%B1%8F%E9%9A%9C
Does the C++ volatile keyword introduce a memory fence?
https://stackoverflow.com/q/26307071/1645289
Does the C++ volatile keyword introduce a memory fence?
It depends on which compiler “the compiler” is. Visual C++ does, since 2005. But the Standard does not require it, so some other compilers do not.
https://stackoverflow.com/a/26307223/1645289
Blogs
Memory Reordering
Understanding memory reordering
https://www.internalpointers.com/post/understanding-memory-ordering
浅谈Memory Reordering
http://dreamrunner.org/blog/2014/06/28/qian-tan-memory-reordering/
C++11中的内存模型上篇 - 内存模型基础
https://www.codedump.info/post/20191214-cxx11-memory-model-1/
C++11中的内存模型下篇 - C++11支持的几种内存模型
https://www.codedump.info/post/20191214-cxx11-memory-model-2/
Understanding Atomics and Memory Ordering
https://dev.to/kprotty/understanding-atomics-and-memory-ordering-2mom
volatile (Thread safe queue)
Creating a thread safe producer consumer queue in C++ without using locks
https://blogs.msmvps.com/vandooren/2007/01/05/creating-a-thread-safe-producer-consumer-queue-in-c-without-using-locks/
Single producer single consumer lock-free queue C++ implementation
https://www.programmersought.com/article/4063419461/
Stay away from Volatile in threaded code?
https://sites.google.com/site/kjellhedstrom2/stay-away-from-volatile-in-threaded-code
C++11’s atomic and volatile, under the hood on x86
https://brooker.co.za/blog/2013/01/06/volatile.html
Tutorials
Stack & Heap
Stack vs Heap Memory in C++
https://www.youtube.com/watch?v=wJ1L2nSIV1s
Efficiency is doing the thing right. Effectiveness is doing the right thing. ― Peter F. Drucker