Skip to content

Busy waiting

Category: Scheduling · Status: stub

One line: Waiting for a condition by checking it in a loop, burning CPU the whole time; worth it for a few nanoseconds inside a spinlock, wasteful for anything longer.

Also called: spinning, spin-waiting, spin loop.

How it connects

flowchart LR
  n_busy_waiting["Busy waiting"]
  n_condition_variable["Condition variable"]
  n_spinlock["Spinlock"]
  n_busy_waiting ---|or| n_condition_variable
  n_spinlock -->|uses| n_busy_waiting
  classDef center stroke-width:3px
  class n_busy_waiting center
  classDef outside stroke-dasharray: 4 3
  class n_condition_variable,n_spinlock outside

In each language

Rust std::hint::spin_loop tells the processor it is in a spin loop
Java Thread.onSpinWait tells the runtime that the caller is busy-waiting
C# SpinWait spins for a while and then starts yielding

Where to read more