CS FundamentalsVery hardGATE CS

A process holds a spinlock and is preempted on a single-CPU system; the next scheduled thread tries to take the same spinlock. What happens, and how do kernels avoid it?

  1. A. The new thread acquires the lock too
  2. B. The CPU detects the deadlock and kills both
  3. C. The new thread spins for its whole time slice uselessly; kernels disable preemption (and often local interrupts) while a spinlock is held
  4. D. Nothing; spinlocks are always safe on one CPU

Correct answer: C. The new thread spins for its whole time slice uselessly; kernels disable preemption (and often local interrupts) while a spinlock is held

The holder cannot release the lock while not running, so spinning wastes the slice (or deadlocks if the spinner never yields, e.g. in an interrupt). Kernel spinlocks therefore disable preemption on the local CPU.

More Operating Systems questions

Exams that ask this topic