Memory Ordering
Memory ordering describes the rules governing how memory operations (loads and stores) become visible to other processors in a multithreaded or multiprocessor system. Modern CPUs and compilers routinely reorder instructions for performance optimization, but in concurrent programs, such reordering can break correctness if not constrained by explicit barriers or atomic operations with defined ordering semantics.
In lock-free programming, memory ordering is not an implementation detail — it is the difference between a correct algorithm and a subtle, intermittent bug that appears only under specific timing conditions. Programming languages expose ordering constraints through memory models: C++ defines memory_order_relaxed, memory_order_acquire, memory_order_release, and memory_order_seq_cst, each trading performance for guarantees of visibility and ordering.
See also: Lock-Free Programming, Compare-And-Swap, Concurrency, Atomic Operation