Spin Or Sleep
A microbenchmark on one lock. The critical section takes ns. When a waiter blocks instead of spinning, the futex sleep, the later wake, and the two context switches cost microseconds, and that cost is paid once per handoff. Eight threads call the lock at the same instant and each runs the critical section exactly once.
Under a pure spin lock the k-th thread to acquire waits
and under a pure sleeping lock each handoff also pays the block-and-wake cost
How long does the last of the eight threads wait under each policy?
Sign in to answer questions and track your progress
Sign In