operating-systems concurrency

Definition

Busy Waiting

Busy waiting (or spinning) is a synchronisation technique where a process repeatedly checks a condition (such as the value of a flag) in a loop until it becomes true. During this time, the process remains in the Running state and continues to consume CPU time.

Mechanism

Busy waiting is commonly used in low-level software and hardware synchronisation where the expected wait time is very short. A typical implementation looks as follows:

while (condition != true) {
    // Do nothing (spin)
}

Advantages and Disadvantages

Advantages

  • Low Latency: There is no overhead from a context switch or kernel intervention, making it faster for extremely short waits.

Disadvantages

  • CPU Inefficiency: The processor wastes cycles that could be used by other processes.
  • Priority Inversion: A high-priority process spinning on a resource held by a low-priority process may prevent the low-priority process from ever running to release the resource.

Alternatives

Modern operating systems generally prefer blocking mechanisms. In these models, a process that must wait is moved to the Blocked state (see Process State Model), allowing the dispatcher to allocate the CPU to another productive task.