Two bad extremes
Pure spinning burns the core while waiting, which is terrible for long waits. Pure blocking parks the thread immediately, which pays an expensive context switch even when the lock would free up in nanoseconds.
The hybrid
The spin then block strategy combines both.
- On a failed acquire, the thread spins a bounded number of times, retrying the atomic check.
- If the lock frees during the spin, it wins cheaply with no context switch.
- If the spin budget runs out, the thread gives up and parks, releasing the core.
The spin window is tuned so that it usually covers the time a critical section holds the lock. Adaptive versions adjust the budget based on recent success.
Why it matters
Most real critical sections are very short. Spinning briefly converts a costly park and unpark into a few cheap retries, while the fallback to blocking keeps long waits from wasting the processor.
Key idea
Spin then block spins for a bounded window to catch short waits without a context switch, then parks the thread when the budget runs out, balancing low latency against wasted cycles.