~/talk

Back to Basics: Concurrency

Talkat CppCon 2020 · 2020-09-14..09-18· [concurrency]
slides:none on file

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

  1. 0:00Intro
  2. 0:44Outline
  3. 1:40What is concurrency?
  4. 3:11Why does C++ care about it?
  5. 5:40The hardware can reorder accesses
  6. 7:43Starting a new thread
  7. 8:37Joining finished threads
  8. 10:58Getting the "result" of a thread
  9. 12:33Example of a data race on an int
  10. 14:51Logical synchronization
  11. 15:57First, a non-solution: busy-wait
  12. 18:09A real solution: std::mutex
  13. 22:18Protection must be complete
  14. 26:19A "mutex lock" is a resource
  15. 31:43Metaphor time!
  16. 32:11Mailboxes, flags, and cymbals
  17. 33:08condition_variable for "wait until"
  18. 38:17Waiting for initialization C++11 made the core language know about threads in order to explain how
  19. 39:07Thread-safe static initialization
  20. 40:10How to initialize a data member
  21. 41:21Initialize a member with once_flag
  22. 43:02C++17 shared_mutex (R/W lock)
  23. 48:53Synchronization with std:: latch
  24. 52:11Comparison of C++20's primitives
  25. 53:48One-slide intro to C++11 promise/future
  26. 57:46The "blue/green" pattern (write-side)
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.