C++20 Memory Model
The C++ memory model as revised for C++20. It adopts the repaired sequential-consistency semantics of Lahav et al. (P0668), strengthening seq_cst atomics and fences so the broken IRIW / SC-fence behaviours of C++11/14/17 become forbidden; and it weakens release sequences (P0982) so that only RMWs — not later relaxed stores by the same thread — continue them. It still does not resolve the thin-air problem, so out-of-thin-air reads remain (unlike RC11). The seq_cst strengthening and the release-sequence weakening pull in opposite directions, leaving C++20 incomparable with the original C11/C++11 model and strictly weaker than RC11. This is also the model Rust normatively adopts for core::sync::atomic: the shipped Rust atomics model is C++20 (not full RC11 — see ORC11, the stronger operational RC11 used to verify Rust's standard library).
Ordering relationships
- Strictly weaker than
- Repaired C11 (RC11) — C++20 adopts RC11's repaired SC (P0668) but, unlike RC11, does not adopt the no-thin-air axiom acyclic(po ∪ rf): it still permits out-of-thin-air / plain load-buffering reads that RC11 forbids. So RC11 is strictly stronger.
- Incomparable with
- C11/C++11 Memory Model — Two-sided: C++20's repaired seq_cst (P0668) forbids the IRIW/SC-fence behaviour that C11/C++11/14/17 allow, while C++20's weakened release sequences (P0982 — only RMWs continue a release sequence) allow a synchronisation outcome C11 forbids. Neither contains the other.
References
- Hans-J. Boehm, Olivier Giroux, Viktor Vafeiadis. P0668R5: Revising the C++ Memory Model. ISO/IEC JTC1/SC22/WG21, 2018.
- Hans-J. Boehm. P0982R1: Weaken Release Sequences. ISO/IEC JTC1/SC22/WG21, 2018.
- Ori Lahav, Viktor Vafeiadis, Jeehoon Kang, Chung-Kil Hur, Derek Dreyer. Repairing Sequential Consistency in C/C++11. PLDI 2017, 2017. doi:10.1145/3062341.3062352
- ISO/IEC. ISO/IEC 14882:2020 — Programming Language C++. ISO Standard, 2020.