Concurrency Improvements in C++20: A Deep Dive
summary
C++20 adds concrete concurrency primitives and shows what to use and why: lock‑free algorithms via compare_exchange (example: an atomic multiply implemented with a CAS loop), atomic_ref to prevent data races on referenced objects (proven with ThreadSanitizer), new atomic wait/notify and atomic smart‑pointer specializations (atomic shared_ptr is thread‑safe but not lock‑free), semaphores, latches and reusable barriers, and cooperative interruption with stop_source/stop_token plus callbacks and an auto‑joining std::jthread. A ping‑pong benchmark of 1,000,000 ping‑pong exchanges reports semaphores and atomics as 10× faster than condition_variable and far simpler to read.
AI-written summary · about
chapters (10)
- 0:00Introduction to concurrency
- 8:21History of atomics in C++
- 12:16Atomic operations and compare exchange
- 20:51C++20 atomic extensions
- 23:23Atomic notifications vs condition variables
- 34:23Ping pong performance comparison
- 45:58Latches and barriers explained
- 53:08Cooperative thread interruption
- 1:03:04Automatic thread joining
- 1:07:18Q&A
