Study Guides/Computer Science/Deadlock Prevention and Avoidance
Study Guide ยท Computer Science

Deadlock Prevention vs Deadlock Avoidance in OS

In Operating Systems, a Deadlock is a situation where a set of processes are blocked because each process is holding a resource and waiting for another resource acquired by some other process. To handle deadlocks, two primary strategies are used: Prevention and Avoidance.

Question (Click to Flip)

What is deadlock prevention in OS?

Answer

Deadlock prevention is a set of methods used to ensure that at least one of the four necessary conditions for deadlock (mutual exclusion, hold and wait, no preemption, circular wait) cannot occur.

Card 1 of 2 free previews

Key Facts

Deadlock Prevention: Breaks at least one of the 4 Coffman conditions.

Deadlock Avoidance: Uses algorithms (like Banker's) to stay in a safe state.

Prevention Strategy: Strict rules, lower resource utilization.

Avoidance Strategy: Requires future knowledge of process requests.

Deadlock Prevention

Deadlock prevention ensures that at least one of the four necessary conditions for a deadlock (Coffman conditions) never holds true.

  1. Mutual Exclusion: Allow resources to be shareable (e.g., read-only files). However, some resources like printers cannot be shared.
  2. Hold and Wait: Require processes to request all needed resources at once before starting execution.
  3. No Preemption: If a process holding some resources requests another resource that cannot be immediately allocated to it, all resources currently being held are preempted (released).
  4. Circular Wait: Impose a total ordering of all resource types and require that each process requests resources in an increasing order of enumeration.

Deadlock Avoidance

Deadlock avoidance does not strictly prevent the four conditions. Instead, the OS dynamically checks the resource allocation state before granting a resource request to ensure that the system never enters an 'unsafe state'.

  • The OS needs prior information about how many resources a process will need over its lifetime.
  • If granting a request leads to a state where a deadlock could happen (unsafe state), the request is delayed.
  • Banker's Algorithm is the most famous algorithm used for deadlock avoidance.

Comparison

FeatureDeadlock PreventionDeadlock Avoidance
ApproachStatic (Rules are set beforehand)Dynamic (Checks at runtime)
Resource UtilizationLow (Resources are often wasted)High (Resources are allocated efficiently)
AlgorithmPreemption, Resource OrderingBanker's Algorithm

Questions and Answers

What is deadlock prevention in OS?+

Deadlock prevention is a set of methods used to ensure that at least one of the four necessary conditions for deadlock (mutual exclusion, hold and wait, no preemption, circular wait) cannot occur.

What is deadlock avoidance?+

Deadlock avoidance is a technique where the OS dynamically analyzes resource requests using algorithms (like Banker's algorithm) to ensure the system never enters an unsafe state where deadlock might occur.

More in Computer Science

Study Smarter with Shinyu.ai

Turn this guide into revision flashcards, a practice exam, or an AI-generated podcast โ€” free, no signup required.