Home › GATE CSE › computerscience › Operating Systems › A SPIN LOCK (or busy-waiting lock) is one in whi…
A SPIN LOCK (or busy-waiting lock) is one in which a thread that finds the lock held
Asleeps and is woken up by the kernel when the lock is released
Bloops continuously checking if the lock is free (busy waiting)
Cthrows an exception
Dterminates the process
Answer & Solution
Correct answer: B. loops continuously checking if the lock is free (busy waiting)
1. OSTEP §28.7 introduces SPIN LOCKS: when a thread can't acquire the lock, it LOOPS (spins) checking the lock state repeatedly until it becomes free.
2. ADVANTAGE: no kernel involvement → very fast IF the lock is held briefly.
3. DISADVANTAGE: wastes CPU cycles while spinning. Bad on single-CPU systems (no other thread can release the lock if the spinner is hogging the CPU).
4. Real systems use spinlocks for short critical sections (e.g. inside kernel code), and BLOCKING (sleep-based) locks for longer waits.
5. Option A describes a BLOCKING lock (mutex with sleep/wakeup). Options C, D are wrong.
_Source: OSTEP Ch 28, §28.7 (Spin Locks With Test-And-Set), p. 6-7._
Related questions
On a MULTI-CORE system, a SPIN LOCK is generallyDisabling INTERRUPTS as a way to implement mutual exclusion on a single-CPU system isA LIVELOCK differs from a DEADLOCK in thatSuppose thread A acquires lock L1, then thread B acquires lock L2. Now A tries to acquire Without atomic hardware support, building a correct mutual-exclusion lock for $N \geq 2$ tA CRITICAL SECTION isLinux's `pthread_mutex_lock()` is typically implemented as a HYBRID:What is the PRIMARY problem with using a SPIN LOCK on a SINGLE-CPU uniprocessor system (wi