Skip to main content

Necessary conditions; deadlock prevention

Short answer

The four necessary conditions for deadlock are mutual exclusion, hold and wait, no preemption, and circular wait. Prevention ensures at least one condition never holds: spooling for mutual exclusion, requesting all resources initially for hold and wait, allowing preemption for no preemption, and imposing a total ordering on resource requests for circular wait.

What are the necessary conditions for deadlock? How can deadlock be prevented?

Necessary conditions for deadlock

  1. Mutual exclusion: a non-sharable resource is held by one process at a time.
  2. Hold and wait: a process holds resources while waiting for more.
  3. No preemption: resources cannot be forcibly removed from a process.
  4. Circular wait: a cycle of processes, each waiting for the next one's resource.

Deadlock prevention

Prevention designs the system so that at least one of the conditions can never occur.

Condition attackedTechniqueDrawback
Mutual exclusionMake resources sharable, spool devices like printersNot possible for all resources
Hold and waitRequest all resources before execution begins, or release all before a new requestLow utilisation, starvation, future needs unknown
No preemptionIf a request is denied, process releases all its held resources; or the OS preempts themOnly for resources whose state can be saved
Circular waitNumber resources; allow requests only in increasing orderHard to find a good ordering for every program

Example of circular wait prevention: resources numbered Scanner = 1, Printer = 2. A process holding the printer cannot ask for the scanner; it must request the scanner first. Hence P and Q cannot wait on each other in a cycle.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Operating System chapter 7 questions →