When Atomics Lose - Architecture‑Dependent Performance of C++ Synchronization
summary
Benchmarks use C++ atomics and std::mutex on real hardware (MacBook M3 Pro and a 64‑core x86 server), running 400 threads, 100k iterations across five primitives: fetch_add vs compare_exchange in ARM (Apple Silicon M3 Pro) vs 64‑core x86. Result: on x86 atomics outperform mutexes consistently; on ARM atomics degrade badly under high contention — retry loops, cache‑line ping‑pong and LLSC/LSE behavior make compare_exchange and seq_cst atomics up to an order of magnitude slower, while mutexes win by blocking threads via futex wake/sleep. Slides and code are posted.
AI-written summary · about
chapters (19)
- 0:00Atomic and mutex performance
- 1:04Atomic and mutex prevent races
- 2:09Locking under contention
- 4:46ARM vs x86 atomics
- 5:06Case study 400 threads
- 7:35Fetch add relaxed vs sequential consistency explained
- 12:13Live sync performance demo
- 16:53ARM high contention results
- 21:45x86 contention results
- 24:16ARM atomics under contention
- 26:49LLSC explained with analogy
- 29:16ABA problem in LLSC
- 30:41Cache line ping-pong impact
- 33:08TSO vs weak memory
- 35:19Weak memory atomic overhead
- 37:49Mutex vs atomics high contention
- 39:34Atomics or mutexes guidance
- 41:41Key takeaways architecture choices
- 42:24Q&A
related talks
01h 14m“C++ atomics, from basic to advanced. What do they really do?”
01h 22mBeyond Sequential Consistency - Leveraging Atomics for Fun & Profit
01h 03mUsing weakly ordered C++ atomics correctly
22mWhat we learned from C++ atomics and memory model standardization
01h 12mThe speed of concurrency (is lock-free faster?)
01h 03mSafety: off --- How not to shoot yourself in the foot with C++ atomics
01h 04mAtomics, Locks, and Tasks (part 2 of 2)
53mAtomics, Locks, and Tasks (part 1 of 2)
