Busy Waiting - aryanjoshi0823/5143-Operating-System GitHub Wiki

What Is Busy Waiting?

Busy waiting, also known as spinning or busy looping, is a process synchronization technique where a process/task waits and continuously checks for a condition to be satisfied before proceeding with execution.

During busy waiting, a process executes instructions to test for a condition, such as the availability of a lock or resource.
Busy waiting is commonly used to achieve mutual exclusion in operating systems.

Example:

For resource availability, consider a scenario where a process needs a resource for a specific program. However, the resource is currently in use and unavailable at the moment, therefore the process has to wait for resource availability before it can continue. This is what is known as busy waiting as illustrated below:

There are two general approaches to waiting in operating systems:

  1. Busy Waiting: Continuously checking for the condition, consuming CPU resources.
  2. Sleeping/Blocked Waiting: The process is put to sleep and awakened only when the condition is satisfied.

Drawback:

  • Loops waste CPU resources, especially for low-priority tasks.
  • High-priority tasks may be delayed due to resource hogging.
  • CPU cycles are spent on unnecessary looping instead of useful computation.