Overview
CAS is the most common atomic primitive used in x86 architectures. It is used to implement 'optimistic' concurrency control: a thread reads a value, calculates a new value, and then uses CAS to update it only if the value hasn't changed in the meantime.
Parameters
- Address: The memory location to check.
- Expected Value: What the thread thinks is currently there.
- New Value: What the thread wants to write.
The ABA Problem
A situation where a value changes from A to B and back to A. A simple CAS will succeed, even though the state has changed. This is often solved using versioning or LL/SC.