1. Gyanastra
  2. Operating Systems
  3. Deadlocks
  4. Definition of Deadlock and Starvation vs Deadlock
Free lesson, no account needed 5 min read 8 practice questions after it
Asked in past papers9 times
  • GATE CSE2021200820042000
  • ISRO2020
  • UGC NET2016201320102006

Operating Systems · Deadlocks

Definition of Deadlock and Starvation vs Deadlock

Overview

A deadlock is a situation in which a set of processes wait for each other, and the events they wait for can never occur. Distinguishing deadlock from starvation matters because starvation ends after some time, while deadlock never does.

Key concepts

  • Deadlock: a set of processes is said to be in deadlock if they wait for the happening of an event caused by the others in the same set.
    If 3–4 processes belong to one set and each is waiting for some other process in the same set to do something, and every one of them is blocked, those events will never occur — this is a deadlock.
  • Starvation: long waiting — a process keeps waiting for a long time.
  • Deadlock (as a form of waiting): infinite waiting — a process gets blocked for an infinite time, and there is no one who is going to get it out of that infinite waiting.
  • Circular waiting: deadlock happens when processes hold some resources/semaphores and each waits for what the other holds.

How it works

  1. Semaphore-based example: one semaphore is taken (held) by one process; another process takes a different semaphore. Each of the two processes then waits for the semaphore held by the other. Both wait for each other → deadlock.
  2. Everyday metaphor — the bike argument: you ask your dad to buy you a bike.
    Dad says: "You learn first, then I will buy it." You say: "You buy it first, then I will learn it." Dad waits for you to learn; you wait for dad to buy.
    Neither event can happen, so the waiting becomes an infinite loop — infinite waiting — a deadlock.
  3. General structure: one process is waiting for the other to perform an event so that it can continue, while the other is waiting for the first — both are waiting for each other, so neither can continue.
  4. Why it is deadlock and not ordinary starvation: if a process is blocked for an infinite time and nothing can pull it out of that infinite wait, it is a deadlock.
    A set of processes each waiting on an event produced by another member of the same set, where those events will never occur, is a deadlock.
Figure. In the semaphore example P1 holds S1 and waits for S2, while P2 holds S2 and waits for S1; the closed cycle is deadlock, infinite waiting with no way out. Starvation is long waiting and may end.

Comparison

AspectStarvationDeadlock
Type of waitingLong waitingInfinite waiting
Can the process come out of it?Yes — after some time the process may come out of starvation and get executedNo — the wait is infinite; the events will never occur, so there is no way out
RelationEvery starvation need not be a deadlockEvery deadlock is also a starvation

Reasoning for the relation: in starvation the process may eventually be executed after some time, so starvation alone does not imply deadlock; but a process stuck forever (deadlock) is certainly waiting for a very long (infinite) time, so every deadlock is a starvation.

Revision summary

  • Deadlock = a set of processes waiting for events caused by other processes of the same set;
    those events never happen, so the wait never ends.
  • Simple identification rule: starvation = long waiting, deadlock = infinite waiting.
  • Every deadlock is a starvation, but every starvation is not a deadlock (starved processes may eventually execute).
  • Test for deadlock in an example: check whether the waiting forms a closed cycle inside one set of processes with no outside event able to break it — if yes, it is a deadlock (infinite wait); if the wait can end after some finite time, it is only starvation.
  • Deadlock arises when processes hold some resources/semaphores and each waits for what the other holds (circular waiting between the two).

Previous-year exam insights

  • Four necessary conditions for deadlock (all must hold simultaneously): mutual exclusion, hold-and-wait, no preemption, and circular wait.
    Asked inUGC NET 2010GATE 2004
  • A deadlock can be detected in a resource-allocation graph by a cycle: a cycle is necessary for deadlock, and with single instances per resource type a cycle is both necessary and sufficient.
    Asked inUGC NET 2016GATE 2021
  • Deadlock prevention removes one of the four necessary conditions; deadlock avoidance uses safe-state/Banker's algorithm with maximum claims; detection-and-recovery allows deadlock and then breaks it.
    Asked inGATE 2004
  • A scheme can be deadlock-free yet not starvation-free (e.g., priority-based resource allocation, or a lock handed to whichever waiter wins the race); deadlock-freedom does not guarantee bounded waiting.
    (Wait-die and wound-wait are deadlock-free and, because a restarted transaction keeps its original timestamp, also starvation-free.)
    Asked inGATE 2004ISRO 2020GATE 2021
  • Starvation (indefinite blocking) can occur without deadlock, e.g., a low-priority process repeatedly overtaken, or a process repeatedly losing a race for a semaphore; it is a liveness/fairness problem, not a circular-wait problem.
    Asked inGATE 2021ISRO 2020
  • In the classic two-semaphore lock-ordering bug, two processes acquiring the same two semaphores in opposite orders can deadlock; imposing a global ordering on resource acquisition prevents circular wait.
    Asked inUGC NET 2013
Pages 1–2 of 2