- LPU MCA Semester 1
- CAP366
- 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 denied | Technique | Drawback |
|---|---|---|
| Mutual exclusion | Make resources sharable (e.g. read-only files, spooling) | Not possible for intrinsically non-sharable resources |
| Hold and wait | Request all resources before starting, or release before requesting more | Low utilisation, possible starvation |
| No preemption | Take resources from a blocked process | Hard for printers and similar devices |
| Circular wait | Number resources and request only in increasing order | Awkward 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
To deny hold and wait, a system requires each process to request all its resources before it starts running. What is the main drawback?
- Processes can no longer be preempted from the CPU when the timer expires
- A circular wait becomes more likely among the waiting processes
- Resources may sit idle for long and a process needing popular resources may starve
- 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.
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?
- R1
- R5
- R3
- 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.