Definition
Busy Waiting
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.