1. LPU MCA Semester 1
  2. CAP366
  3. Unit 6

CAP366 · Unit 6: Deadlocks

Methods for handling deadlocks and prevention

8 practice questions · in the ETE syllabus

Key points

  • Four strategies: ignore, prevent, avoid, detect and recover
  • Prevention denies one of the four necessary conditions
  • Resource ordering prevents circular wait
  • Avoidance needs maximum claims in advance; prevention does not

There are four ways to treat deadlocks: ignore the problem (the ostrich approach used by most general-purpose systems), prevent it, avoid it, or detect and recover.

Prevention makes sure at least one of the four necessary conditions can never hold:

Condition deniedTechniqueDrawback
Mutual exclusionMake resources sharable (e.g. read-only files, spooling)Not possible for intrinsically non-sharable resources
Hold and waitRequest all resources before starting, or release before requesting moreLow utilisation, possible starvation
No preemptionTake resources from a blocked processHard for printers and similar devices
Circular waitNumber resources and request only in increasing orderAwkward for programmers

Why ordering works: along any chain of waits the resource numbers strictly increase, so the chain cannot return to its start. If a process holding R3 needs R1, it must release R3 and request R1 then R3 again.

Avoidance differs from prevention: it needs each process's maximum demand in advance and grants a request only if the system stays in a safe state.

Exam trap: prevention constrains how requests are made by design; avoidance checks every request against future safety.

Try two questions

Question 1 · Tier 3, Apply

To deny hold and wait, a system requires each process to request all its resources before it starts running. What is the main drawback?

  1. Processes can no longer be preempted from the CPU when the timer expires
  2. A circular wait becomes more likely among the waiting processes
  3. Resources may sit idle for long and a process needing popular resources may starve
  4. Mutual exclusion is lost for the resources that are requested early
Show the answer

C. Holding everything from the start wastes resources that are only needed later, and a process needing several popular resources may wait for ever.

Why not A: Timer preemption of the CPU is unrelated to resource requests.

Why not B: Requesting everything at once removes hold and wait and does not encourage cycles.

Why not D: Resources stay exclusive; only the request pattern changes.

Question 2 · Tier 3, Apply

Resources R1 to R5 are numbered and a process may only request a resource with a higher number than any it holds. A process that currently holds R2 and R4 makes a new request. Which request is permitted?

  1. R1
  2. R5
  3. R3
  4. R2
Show the answer

B. The new request must be numbered above the highest held resource, R4, so only R5 qualifies.

Why not A: R1 is lower than the held R4 and would violate the ordering.

Why not C: R3 is lower than R4, which is already held.

Why not D: R2 is already held and lower than R4.