Lock-free programming coordinates threads without mutexes, using atomic compare-and-swap (CAS) loops so at least one thread always makes progress even if others stall. No thread can be blocked by another holding a lock.
CAS
Compare-and-swap atomically sets a location to a new value only if it still holds the expected old value; otherwise it fails and you retry. It's the primitive behind lock-free stacks, queues, and counters.
CAS(addr, expected, new):
if *addr == expected: *addr = new; return true # atomic, indivisible
else: return false
old, next;
{
old = value.get();
next = old + ;
} (!value.compareAndSet(old, next));
