Single Producer Single Consumer Lock-free FIFO From the Ground Up
Talkat CppCon 2023 · on Thursday, 2023-10-05· at 14:00· Maple 3/4/5, 6700 North Gaylord Rockies Boulevard·
summary
Builds a real Single‑Producer Single‑Consumer lock‑free wait‑free FIFO from first principles, with code on GitHub, using atomic 64‑bit cursors and then replacing sequentially‑consistent ops with relaxed acquire/release ordering and per‑cursor padding (std::hardware_destructive_interference_size) to eliminate false sharing. Adds a proxy pusher to halve memcpy and compares against Boost.Lockfree and Rigtorp variants. Reports measured throughput jumps: ~12–13M → ~50M → ~165M ops/s depending on atomics, indexing (mod vs power‑of‑two) and padding; unit tests and ThreadSanitizer confirm correctness.
AI-written summary · about
chapters (13)
- 0:00Introduction
- 2:12Why build custom lock-free FIFO
- 5:03SPSC FIFO basics
- 10:04FIFO class structure
- 13:15Push and pop operations
- 16:31Debugging data races
- 20:25Fixing data races with atomics
- 26:48Testing and performance
- 27:34Optimizing with relaxed atomics
- 34:18Caching cursors for speed
- 37:30Reducing copies with smart pointers
- 46:11Benchmarks and comparisons
- 50:46Q&A
related talks
01h 01mBuilding a Lock-free Multi-producer, Multi-consumer Queue for Tcmalloc
01h 02mLock-free programming for real-time systems
54mThe Upcoming Concurrency TS Version 2 for Low-Latency and Lockless Synchronization
01h 33mThe Foundation of C++ Atomics: The Knowledge You Need to Correctly Use C++ Atomics
01h 01mSmarter Cpp Atomic Smart Pointers - Efficient Concurrent Memory Management
55mMemory Model: Get your shared data under control
39mSafety first
01h 01mSecurity: from Transistors to Compilers
