Back to Basics: Concurrency
summary
Explains concrete C++ mechanisms: std::thread starts immediately, data races on plain variables are undefined behavior, atomics avoid UB for simple counters, and thread-safe static initialization guarantees only one initializer runs. Demonstrates protecting shared state with a mutex plus RAII (lock_guard/unique_lock), how condition_variable wait atomically releases and reacquires the lock for a producer/consumer token queue, and shows C++20 primitives semaphore/latch/barrier and std::async/std::future caveats about thread creation and lack of a standard thread pool.
AI-written summary · about
chapters (26)
- 0:00Intro
- 0:44Outline
- 1:40What is concurrency?
- 3:11Why does C++ care about it?
- 5:40The hardware can reorder accesses
- 7:43Starting a new thread
- 8:37Joining finished threads
- 10:58Getting the "result" of a thread
- 12:33Example of a data race on an int
- 14:51Logical synchronization
- 15:57First, a non-solution: busy-wait
- 18:09A real solution: std::mutex
- 22:18Protection must be complete
- 26:19A "mutex lock" is a resource
- 31:43Metaphor time!
- 32:11Mailboxes, flags, and cymbals
- 33:08condition_variable for "wait until"
- 38:17Waiting for initialization C++11 made the core language know about threads in order to explain how
- 39:07Thread-safe static initialization
- 40:10How to initialize a data member
- 41:21Initialize a member with once_flag
- 43:02C++17 shared_mutex (R/W lock)
- 48:53Synchronization with std:: latch
- 52:11Comparison of C++20's primitives
- 53:48One-slide intro to C++11 promise/future
- 57:46The "blue/green" pattern (write-side)
related talks
47mConcurrent Programming in C++
01h 24mConcurrency in C++20 and Beyond
01h 08mBetter Code: Concurrency
59mAn Introduction to Multithreading in C++20
53mAtomics, Locks, and Tasks (part 1 of 2)
01h 00mConcurrency in C++20: A Deep Dive
01h 00mConcurrency Improvements in C++20: A Deep Dive
01h 28mAn Introduction to Multithreading in C++20
