compare-and-swap
An atomic step that writes a new value only if memory still holds the value you expected, and tells you whether it did.
Compare-and-swap atomically compares *p with an expected value and, if equal, stores a desired value; it reports success and the value observed (x86-64 lock cmpxchg with the expected value in rax; ARM64 LSE cas; C++ compare_exchange_strong/weak).
Examples
CAS(&x, 5, 6) sets
xto 6 only if it still holds 5, and reports whether it did.