What is Spinlock?

A lock that waits by repeatedly checking the lock variable in a loop. Fast for short waits, but it keeps using the CPU while waiting.

Field: Multicore & Synchronization

Spinlock in the explanations

Questions that mention Spinlock (4)

  1. Which describes a spinlock?
  2. In which situation is a spinlock least suitable?
  3. Why does a spinlock usually wait with ordinary reads and use an atomic instruction only when the lock looks free (test-and-test-and-set), instead of retrying the atomic write directly?
  4. Which correctly compares a mutex (a lock that sleeps while waiting) with a spinlock?

Related terms

Atomic instruction Mutex Interrupt CPU time Context switch ABA problem Acquire-release semantics Barrier synchronization Bus snooping Compare-and-swap

Back to the glossary