Atomic’s memory orders, what for?
summary
Explains concrete effects of C++11 std::atomic memory_order options using microtests: plain int gets optimized away, volatile increments fail, atomic increments work but are slower; relaxed gives atomicity only (counters OK) but no cross-variable visibility; release/acquire pairs make writes-before the store visible to a reader that does an acquire load (useful for publishing non-atomic data); consume is impractical and discouraged; sequentially consistent enforces a global order at runtime cost and prevents subtle store/load reorderings that can produce r1==r2==0 on weak ARM cores.
AI-written summary · about
chapters (13)
- 0:00Introduction to Atomics
- 2:35Physics and Simultaneity
- 5:53Atomic vs. Volatile
- 11:48Memory Ordering Basics
- 16:02Execution Order and Bugs
- 19:39Sequence Before Relation
- 25:06Synchronizes With
- 30:24Relaxed Memory Ordering
- 35:32Release Acquire Semantics
- 40:29Memory Order Consume
- 50:08Atomic Chaining Example
- 53:53Sequential Consistency
- 1:17:26Reordering and Conclusions
related talks
01h 03mUsing weakly ordered C++ atomics correctly
01h 01m“C++11/14/17 atomics and memory model..."
22mWhat we learned from C++ atomics and memory model standardization
01h 14m“C++ atomics, from basic to advanced. What do they really do?”
43mC++ Atomics...
33mAtomic break down: understanding ordering
01h 03mSafety: off --- How not to shoot yourself in the foot with C++ atomics
01h 22mBeyond Sequential Consistency - Leveraging Atomics for Fun & Profit
