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/

https://stackoverflow.com/a/8833218/1645289

volatile

Single producer single consumer command queue
https://codereview.stackexchange.com/a/152338

Memory barrier (Memory fence)

Understanding c++11 memory fences
https://stackoverflow.com/questions/13632344/understanding-c11-memory-fences

Memory barrier
https://en.wikipedia.org/wiki/Memory_barrier

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.

Reference:
https://stackoverflow.com/a/26307223/1645289

Blogs

Memory Reordering

浅谈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/

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