Lock-Free Programming in Modern C++ | ACCU 2017

Added:

Modern Lock-Based Concurrency and Message Passing (The Case Against Lock-Free Complexity)

While lock-free programming is intellectually stimulating, a strong counterpoint exists within systems engineering: for the vast majority of applications, lock-free structures are considered an anti-pattern due to extreme complexity, maintenance overhead, and susceptibility to subtle bugs like the ABA problem and memory reclamation issues. Furthermore, modern hardware and software techniques often make optimized lock-based concurrency superior. Techniques such as Flat Combining—where a single thread combines and executes operations on behalf of others—frequently outperform lock-free structures under high thread contention. Additionally, high-level abstractions like the Actor Model, message passing, and Software Transactional Memory (STM) dramatically reduce cognitive load and development time while providing comparable, or even superior, scalability and safety. Many systems architects argue that lock-free programming should be treated as a highly specialized niche of last resort, rather than a standard tool for modern multi-threaded C++.

Fundamental multithreading in C++, including threads, mutexes, condition variables, and avoiding basic data races.
Basic CPU architecture concepts, such as cache hierarchies, cache coherency protocols, and hardware-level instruction reordering.
Familiarity with standard data structure implementations, particularly linked lists and FIFO queues.
The concept of atomic operations and the limitations of traditional lock-based synchronization.
Deep dive into C++ memory ordering semantics, specifically distinguishing between sequentially consistent, acquire-release, and relaxed memory orderings.
Advanced memory reclamation techniques in lock-free programming, such as Hazard Pointers and Epoch-Based Reclamation (EBR) to safely handle the ABA problem.
Designing and analyzing other complex lock-free and wait-free data structures, such as lock-free stacks, deques, and flat-combining structures.
Performance profiling and benchmarking of concurrent algorithms under high thread contention using tools like Google Benchmark, Intel VTune, or perf.
19.6K views256likes1:31:34@ACCUConfOriginal Release: 2017-05-05

Lock-free programming enables thread-safe data sharing without locks, which is essential for real-time systems where blocking operations are unacceptable; modern C++ provides std::atomic as a portable, thread-safe generic type that implements lock-free operations through atomic load/store/exchange/compare_exchange member functions, allowing developers to implement lock-free data structures like queues that guarantee progress without mutual exclusion, though implementing such structures requires careful handling of memory ordering, compare-exchange patterns, and understanding the distinction between atomic and lock-free guarantees.