Compare-and-Swap CAS Patterns
Implement lock-free updates with compare_exchange_weak and strong.
The CAS Primitive
Compare-and-swap atomically reads, compares, and conditionally writes. The foundation of most lock-free algorithms.
C++ Compare Exchange
Two variants in std::atomic:
compare_exchange_strong(expected, desired)— succeeds when current equals expectedcompare_exchange_weak(expected, desired)— may fail spuriously
All lessons in this course
- std::atomic and Memory Orders
- Compare-and-Swap CAS Patterns
- Lock-Free Queue Implementation
- Hazard Pointers and the ABA Problem