1. Gyanastra
  2. Operating Systems
  3. Semaphores and Mutex
  4. Busy Waiting and Priority Inversion
Free lesson, no account needed 5 min read 7 practice questions after it
Asked in past papers5 times
  • GATE CSE20171997
  • ISRO20232013
  • UGC NET2006

Operating Systems · Semaphores and Mutex

Busy Waiting and Priority Inversion

Overview

Busy waiting is the spin in the entry section that every synchronization mechanism studied so far shares: a process that cannot enter the critical section keeps testing the condition in an infinite loop, and the CPU, unable to tell that the process is doing no useful work, executes that loop for the whole time slice.
Priority inversion is the stall that follows from it: a high-priority process preempts a low-priority process that is inside its critical section, then spins waiting for the lock the low-priority process can never release.

Key concepts

  • Busy waiting: when a process reaches the entry section and is not allowed to enter the critical section, it does not give up the CPU; it keeps testing the condition in an infinite loop.
    The CPU keeps executing this loop because it cannot tell that the process is doing no useful work, so the entire CPU time slice allotted to that process by the scheduler is wasted.
  • Priority inversion: a situation in which a high-priority process is forced to wait (indefinitely) for a low-priority process, while the low-priority process itself never gets the CPU to finish its critical section — so both processes are stuck.
  • Source of busy waiting: lock variable, turn variable, TSL (Test-and-Set-Lock) and Peterson's solution were all examined. Lock variable and turn variable are "out of the race" (not correct/acceptable solutions).
    Peterson's solution and TSL are perfect — they work correctly and enforce mutual exclusion — but both share one common drawback: whenever such a synchronization mechanism is implemented, busy waiting appears.
  • Scope: priority inversion is possible in all the solutions discussed so far — Peterson's, TSL, and any other solution that uses busy waiting.
  • Trial-room analogy: the critical section is a trial room with one person already inside.
    The people outside do not wait quietly — they keep continuously knocking on the door saying they want to get in, while the person inside never comes out.
    This continuous knocking is exactly the busy-waiting behaviour of a process spinning in the entry section.

How it works

  1. Consider a process structure with three parts: entry section → critical section → exit section.
  2. A low-priority process L is currently inside the critical section.
  3. Suddenly a high-priority process H arrives in the system.
  4. Because H has higher priority, the scheduler runs H first and preempts L — even though L is in the middle of its critical section.
  5. H now reaches the entry section and finds the critical section occupied (the lock/flag is held by L), so H falls into an infinite loop in the entry section (busy waiting).
  6. L, the low-priority process, was preempted and never gets a chance to run again, so it can never reach its exit section to release the lock.
  7. Result: H is stuck in the entry section forever, and L never completes its critical section — a deadlock-like stall. This is the priority inversion problem.
Gantt chart: Busy Waiting and Priority Inversion
Figure. Busy Waiting and Priority Inversion

Comparison

SolutionCorrect / works?Busy waiting present?Priority inversion possible?
Lock variableOut of the race (not acceptable)YesYes (general statement: all discussed solutions)
Turn variableOut of the race (not acceptable)YesYes
Peterson's solutionPerfect — enforces mutual exclusion correctlyYesYes
TSL (Test-and-Set-Lock)Perfect — enforces mutual exclusion correctlyYesYes

The entry-section spin (while (flag/condition);) is the shared source of both columns.

Revision summary

  • Busy waiting = a process keeps looping in the entry section instead of being blocked;
    the scheduler's allotted CPU time slice is completely wasted.
  • Peterson's solution and TSL are logically correct solutions, but they are not efficient because of busy waiting.
  • Priority inversion sequence to memorise: low-priority process inside CS → high-priority process arrives → preempts the low-priority process → high-priority process spins in the entry section → low-priority process never resumes → both stuck.
  • Priority inversion is possible in every solution that uses busy waiting (Peterson's, TSL, and all the others discussed).
  • The cure direction: instead of spinning ("continuously knocking on the door"), a process that finds the critical section occupied should go to sleep and be woken up when the process inside leaves — i.e. mutual exclusion without busy waiting.

Previous-year exam insights

  • Priority inheritance protocol: when a high-priority task blocks on a lock held by a lower-priority task, the holder temporarily inherits the waiter's priority until it releases the lock, preventing medium-priority tasks from preempting it; the priority is restored afterwards.
    Asked inISRO 2023ISRO 2013
  • A non-reentrant lock cannot be re-acquired by the thread already holding it; re-acquisition blocks (or deadlocks) the thread.
    A reentrant lock records the owning thread and a recursion count so the owner can re-acquire it.
    Asked inGATE 2017
  • With blocking locks, a thread waiting for a lock is put to sleep and does not consume CPU; busy waiting (spinlock) wastes the time slice but avoids context-switch overhead and is preferred for very short critical sections on multiprocessors.
  • Deadlock with locks: if threads acquire multiple locks in inconsistent order, a cycle of waiting can form; the standard prevention is a global ordering of lock acquisition.
    Asked inGATE 2017
  • Priority inversion requires preemptive priority scheduling; with non-preemptive scheduling or equal priorities it cannot occur.
    Priority ceiling protocol is an alternative to inheritance that also prevents deadlock.
    Asked inISRO 2013
  • Semaphore/mutex operations: P/wait decrements and blocks if the value would go negative; V/signal increments and wakes a blocked process.
    Blocking implementations avoid busy waiting, unlike spinlocks.
Pages 1–2 of 2