Home › GATE CSE › computerscience › Operating Systems › Suppose thread A acquires lock L1, then thread B…
Suppose thread A acquires lock L1, then thread B acquires lock L2. Now A tries to acquire L2 while B tries to acquire L1. What is this situation called?
AStarvation
BRace condition
CPriority inversion
DDeadlock
Answer & Solution
Correct answer: D. Deadlock
1. DEADLOCK occurs when two or more threads are each waiting for resources held by the other(s) — none can proceed.
2. The example above: A holds L1, wants L2; B holds L2, wants L1. Neither can advance until the other releases — they're locked in a permanent wait.
3. Four CONDITIONS for deadlock (Coffman conditions): mutual exclusion + hold-and-wait + no preemption + circular wait. All four must hold for deadlock to occur.
4. STARVATION (option A) is different: a thread is repeatedly skipped by the scheduler but isn't fundamentally blocked. RACE (option B) is incorrect ordering of independent ops. PRIORITY INVERSION (option C) is when a low-priority thread holds a lock a high-priority thread needs.
_Source: OSTEP Ch 32 (Deadlock — referenced from Ch 28) + general OS theory._
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 thatWithout 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 (wiA LOCK is considered FAIR if