futex_wait suspends an execution only when a specified memory address still contains an expected value. It acts as a wait-queue primitive rather than a mutex itself. section 12.3.1
Calling futex_wait(addr, value) produces one of two outcomes:
- Matching value: suspends the caller and places it at the back of the queue associated with that address. section 12.3.1
- Different value: returns immediately, allowing execution to continue without sleeping. section 12.3.1
A lock can combine an atomic compare-and-swap with futex_wait: failed acquisition waits only while the lock still has the expected locked state. Unlocking stores zero and wakes a waiter. section 12.3.1
A contention-aware version marks the lock with waiters, using value 2, and retries after waking. This can avoid unnecessary system calls when no execution is waiting. section 12.3.2
Compare the matching-value suspension path with the nonmatching-value immediate-return path. section 12.3.1
