Learning path

Full curriculum

Full curriculum

Unit content

Lock-free and wait-free progress guarantees

Avoiding locks does not automatically make a concurrent algorithm safe or fast. Non-blocking algorithms are classified by the progress they guarantee when operations interfere.

A lock-free algorithm guarantees system-wide progress: in any sufficiently long execution, some operation completes. One delayed thread cannot permanently block every other thread by holding a mutex.

A wait-free algorithm gives the stronger guarantee that every operation completes after a bounded number of its own steps, regardless of what other threads do.

Many lock-free updates use a compare-and-swap retry loop:

repeat:
    old = atomic_load(x)
    new = f(old)
until compare_and_swap(x, old, new)

If another thread changes x first, the compare-and-swap fails and the operation retries with the new state. Contention can therefore cause repeated work even though the system as a whole keeps progressing.

Progress guarantees are distinct from correctness. An algorithm can be race-free but deadlock, or lock-free but compute the wrong value. Memory-ordering rules, invariants and reclamation of shared objects must still be correct.

Non-blocking designs are valuable when blocking or lock ownership is problematic, but their stronger guarantees often require more complex reasoning than ordinary mutex-based code.