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?
- A. The new thread acquires the lock too
- B. The CPU detects the deadlock and kills both
- C. The new thread spins for its whole time slice uselessly; kernels disable preemption (and often local interrupts) while a spinlock is held
- 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
- Read-copy-update (RCU) is used for read-mostly kernel data. What is its key idea?
- A reader-writer lock is used where reads are 99% of operations and each read is very short. Why might it perform WORSE than a plain mutex…
- A seqlock lets readers proceed without blocking writers. A reader reads the sequence number, reads the data, then rereads the sequence…
- A condition-variable based bounded buffer uses a single condition variable cv for both 'not full' and 'not empty', and signals with…
- Which statement about deadlock in a system with only ONE resource type that has 10 instances is correct?
- What is the main drawback of deadlock prevention by requiring a process to request ALL its resources before starting (breaking…