“C++ atomics, from basic to advanced. What do they really do?”
summary
Benchmarks show a mutex with a per-thread local accumulator outruns naive atomic increments: the “wait-free” atomic-plus-equals version runs slower and scales poorly on a 120-core Broadwell because cache-line bouncing and false sharing dominate. Sequentially-consistent atomic stores cost about 15x slower than relaxed stores on some paths; x86’s xadd is acquire-release so relax won’t help there. Alignment and padding decide is_lock_free depends on alignment, compare_exchange has compare_exchange_weak can spuriously fail and needs careful acquire/release ordering to publish non-atomic data safely.
AI-written summary · about
chapters (16)
- 0:00Intro
- 1:15Demonstration
- 3:22General conclusion
- 4:22What is atomicity
- 5:13What is increment
- 6:26How does increment work
- 8:15How does atomics work
- 10:33Types of atomics
- 11:00Atomic operations
- 17:08Compare and swap
- 26:30Secrets
- 32:38Cache line
- 37:37Nonatomic operations
- 43:13Memory barriers
- 48:51Memory order
- 53:08Memory
related talks
01h 22mBeyond Sequential Consistency - Leveraging Atomics for Fun & Profit
01h 03mUsing weakly ordered C++ atomics correctly
43mWhen Atomics Lose - Architecture‑Dependent Performance of C++ Synchronization
01h 03mSafety: off --- How not to shoot yourself in the foot with C++ atomics
01h 28mAtomic’s memory orders, what for?
01h 01m“C++11/14/17 atomics and memory model..."
01h 00mConcurrency in C++20: A Deep Dive
22mWhat we learned from C++ atomics and memory model standardization
