C++ Details of Asymmetric Fences
Summary
This post by Ryan Chung explores Linux membarrier and the concept of asymmetric fences for concurrency in C++. It covers the light compiler barrier implementation (asymmetric_thread_fence_light) and the heavy kernel barrier path (membarrier via MEMBARRIER_CMD_PRIVATE_EXPEDITED), with a discussion of how these primitives enable fast paths on the common case and heavier synchronization on the slow path. The article walks through Dekker's example, three cases of memory ordering, and the implications for the C++ memory model and LKMM, including critical LKMM litmus tests and debates about formalizing asymmetric fences in the standard. It also includes detailed kernel-level explanations of the ordering guarantees and references to Folly, Linux docs, and standardization proposals.