Lock-Based and Lock-Free Multithreading with C++2011
Highlights
- An introduction to general in-process concurrency principles with an eye on the new facilities for threading introduced by C++2011
- A thorough overview of the C++2011 memory model and its effect on application correctness and performance
- A principled walk through lock-based (classic) and lock-free (new) approaches to multithreading
- Comparison and contrast with message passing and other approaches to concurrency
Attendee profile
Systems-level programmers who are using or plan to use multiple threads in their C++ applications. C++ knowledge is assumed, but not C++2011 knowledge, which will be introduced as needed. Use of C++2011 recommended but not necessary.
Outline
- The C++2011 memory model and why you care
- Why you care
- Observable behavior
- Compiler optimizations
- Undefined behavior
- Implications
- Single-threading rules and multi-threading rules
- Program order
- Sequential consistency
- Memory Models
- Memory access reorderings
- Hardware memory models
- The C++2011 memory model
- The contract
- Memory locations
- Bitfields
- Data races
- C++2011 tools
- Mutexes and interaction with the memory model
- std::atomics
- Load and store
- Read-modify-write
- CAS
- Interaction with the memory model
- volatile
- Implementing the Double-Checked Locking Pattern correctly
- Low-level atomics; happens-before relations
- Peterson's algorithm
- Dekker's algorithm
- Summary and further information
- Why you care
- Lock-Based Threading
- Definitions
- Concurrent and distributed processes
- Races and deadlocks
- Lock-based programming review
- Principles
- Advantages
- Liabilities
- Tips & tricks with examples
- Strongly prefer scoped locking
- Minimize work inside critical sections
- Do work on the side, lock, and swap
- Push copies into parameters
- Spinlocks need extreme care
- Penny foolish may be pound wise
- Compose functions judiciously
- Don't return handles to shared data
- Prefer read-only sharing
- Best synchronization is no synchronization
- Single-object vs. multi-object locking transactions
- Definitions
- Lock-free Threading
- Good-bye, classic multithreading
- Hello, modern multithreading
- Sequential vs. relaxed consistency
- Intel's consistency rules
- Mother of all tips
- Atomic operations
- The impossibility and universality principles
- CAS
- Defining terms
- Brief history
- Advantages and liabilities
- CAS-based programming
- Limiting memory consumption in CAS-based programming
- Conclusion