A spinlock makes a thread busy-wait in a loop until the lock is free, wasting CPU but avoiding a context switch; it is appropriate for very short critical sections on multicore systems, and in kernels where sleeping is not allowed (such as interrupt handlers).
A mutex puts the waiting thread to sleep, which is better for longer critical sections or when the lock holder may block; on a single core, spinning is useless because the holder cannot run while you spin.
Loading…