Best Practices for Concurrency
summary
Shows concrete failures and fixes: a reader‑writer example that silently writes via map default initialization and produces a data race; summing 100 million elements where a naive lock guard slows four threads to less than 2× because of RAM contention; use local aggregation, atomics only when appropriate, and expect Amdahl limits. Recommends tools: ThreadSanitizer for races, cppmem to enumerate interleavings and visualize the memory model, and existing lock‑free libraries like Boost.Lockfree rather than rolling custom ABA‑prone structures. Also notes futures destructor blocking, jthread interrupt tokens, and prefer tasks over raw threads.
AI-written summary · about
chapters (18)
- 0:00Intro
- 0:47Best Practices for Concurrency
- 1:28Code Reviews
- 4:13Minimise Sharing
- 7:01Minimise Waiting (Amdahl's Law)
- 8:23Use Code Analysis Tools (ThreadSanitizer)
- 10:48Use Code Analysis Tools (CppMem)
- 16:52Use Pure Functions
- 20:58Use Tasks instead of Threads
- 23:10Don't use Fire and Forget Futures
- 27:19Cooperative Interruption of std::thread
- 29:16Use Tasks instead of Condition Variables
- 32:23Condition Variables are hard to use
- 34:29Pack Mutexes into Locks
- 36:40Minimal Locking
- 42:28Don't Program lock-free: ABA
- 45:14Use Proven Patterns
- 49:02Don't Reinvent the Wheel
related talks
59mThreads and Locks must Go
01h 07mAn Introduction to Multithreading in C++20
59mMultithreading 101: Concurrency Primitives From Scratch
48mReal time 101
01h 00mLock-Free Programming (or, Juggling Razor Blades), Part I
01h 04mConcurrency TS2: Improved C++ Concurrency and Lock-free Programming
56mThe C++ Execution Model
56mReader-Writer Lock versus Mutex
