Generic Locking in C++
summary
Library used in production at Facebook (thousands of uses, ~7,000 occurrences) implements generic locking by wrapping any T as synchronized<T,SharedMutex> that stores the data and a mutable mutex. Calls use operator-> returns a locked proxy which constructs a temporary lock object (RAII) so locks by constness (const=shared, non-const=exclusive). Macros like synchronized and synchronized_con shadow a local L-value so code runs inside the critical section; dual-synchronize orders locks by pointer address to avoid deadlock and unsynchronize temporarily disables locking.
AI-written summary · about
chapters (28)
- 0:00Introduction
- 4:13Volatiles
- 6:12Multithreading
- 9:22Cx1x
- 10:09STD Containers
- 14:04Encapsulation
- 19:36Implementation
- 20:01Synchronous
- 22:43Build from data
- 23:08Cycle detection
- 26:39Synchronized pipe
- 28:35Recap
- 31:50Locking Pointer
- 32:23Move
- 33:43Parse
- 35:02LogPointer
- 35:22C Begin
- 37:16You Know That Macro
- 38:02Rookie Mistake
- 40:19Synchronized Statement
- 41:42Macro Trick
- 45:07Synchronization
- 46:05Expression
- 46:25Two Arguments
- 50:56Facebook
- 54:01dot
- 56:17magic macro
- 56:27Synchronize
related talks
01h 05m“The Continuing Future of C++ Concurrency"
26mConcurrency: Unlocking a Solution
51mMemory Model: Get your shared data under control
28mEnd-to-end Deadlock Debugging Tools at Facebook
01h 06mLocks are tricky — let's understand them by building one
01h 11mLock-Free Programming (or, Juggling Razor Blades), Part II
39mLive Lock-Free or Deadlock (Practical Lock-free Programming)
01h 00mConcurrency in C++20: A Deep Dive
