Lock-Free Queue Implementation
Walk through the design of a single-producer single-consumer lock-free queue.
Why Lock-Free Queues?
Queues with mutexes can become bottlenecks under high contention. A lock-free queue lets producers and consumers progress concurrently.
SPSC vs MPMC
Two flavors:
- SPSC — single producer, single consumer (simplest, fastest)
- MPMC — multiple producer, multiple consumer (most general)
SPSC is the natural choice when you control both ends.
All lessons in this course
- std::atomic and Memory Orders
- Compare-and-Swap CAS Patterns
- Lock-Free Queue Implementation
- Hazard Pointers and the ABA Problem