Spin Lock

Noun · Development

Definitions

  1. A low-level mutual exclusion primitive where a thread repeatedly checks (spins on) an atomic flag in a tight loop rather than yielding the CPU to the scheduler. Efficient when the expected wait time is shorter than the overhead of a context switch — commonly used in OS kernels and real-time systems — but wastes CPU cycles if held too long.

    In plain English: A lock where the waiting thread keeps checking 'is it free yet?' in a tight loop instead of going to sleep, which is fast for very short waits.

    Example: "The lock is held for fewer than 50 nanoseconds, so a spin lock outperforms a mutex here by avoiding the context switch."

Related Terms