Lock-free programming with modern C++
summary
Uses C++11/14's std::atomic and the standard memory model to demonstrate a fixed-capacity ring buffer (size = N+1) implemented as a single-producer/single-consumer FIFO that is actually wait-free: push does an atomic store of the element then advances the index, pop loads then advances the index. Shows compare_exchange (strong/weak), is_lock_free, default sequentially-consistent ordering, and pitfalls with floats and nontrivial types. Extending to multiple consumers requires making per-slot accesses atomic or switching to pointer swaps plus explicit lifetime management; recommends using Boost.Lockfree or JUCE AtomicFIFO rather than reinventing it.
AI-written summary · about
chapters (19)
- 0:00Introduction
- 1:54Overview
- 3:32Lock types
- 6:33Time constraints
- 12:26Lockfree guarantees
- 16:10Lock Reprogramming
- 20:01Atomic
- 25:17Floats
- 28:42Weak vs Strong
- 31:10Atomic vs Lockfree
- 32:38Is Lockfree
- 33:55Instances
- 35:44Why do they exist
- 36:59The code
- 39:41Exchange between threads
- 44:23Lockfree queue
- 47:39Dataraces
- 50:33Implementation
- 56:28Wait for you
related talks
01h 30mLive Lock-Free or Deadlock (Practical Lock-free Programming)
01h 05mAn Interesting Lock-free Queue - Part 2 of N
01h 11mLock-Free Programming (or, Juggling Razor Blades), Part II
01h 03mSafety: off --- How not to shoot yourself in the foot with C++ atomics
01h 00mConcurrency in C++20: A Deep Dive
01h 38mLock-free Programming is Dead - Long Live Lock-free Programming!
01h 00mConcurrency Improvements in C++20: A Deep Dive
39mLive Lock-Free or Deadlock (Practical Lock-free Programming)
