Docsity

Deadlocks: Characterization, Prevention, Avoidance, and Detection, Slides of Operating Systems

Partial preview of the text

Download Deadlocks: Characterization, Prevention, Avoidance, and Detection and more Slides Operating Systems in PDF only on Docsity!

DEADLOCKS

System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention, Avoidance, and Detection Recovering from Deadlock Combined Approach to Deadlock Handling

The Deadlock Problem

  • A set of blocked processes each:
    • holding and waiting to acquire a resource held by another process in the set.
  • Example
    • System has 2 tape drives.
    • P1 and P2 each hold one tape drive and each needs another one.

Bridge Crossing Example

  • Traffic only in one direction.
  • Resource: each section of a bridge.
  • If deadlocked: can be resolved if one car backs up

(preempt resources and rollback).

  • Several cars may have to be backed up if a

deadlock occurs.

  • Starvation is possible.

Traffic Deadlock

Deadlock Characterization

  • Mutual exclusion:
    • only one process at a time can use a resource.
  • Hold and wait:
    • a process holding at least one resource is waiting to acquire additional resources held by other processes.

Deadlock may arise if 4 conditions hold simultaneously:

Deadlock Characterization

3. No preemption:

  • a resource can be released only voluntarily by the process holding it, after that process has completed its task.

4. Circular wait:

∃ a set {P 0 , P 1 , …, Pn} of waiting processes s.t.:

  • P 0 is waiting for a resource that is held by P 1 ,
  • P 1 is waiting for a resource that is held by P 2 , …,
  • Pn– 1 is waiting for a resource that is held by Pn, and
  • Pn is waiting for a resource that is held by P 0.

Resource-Allocation Graph

  • Process:
  • Resource Type with 4 instances:
  • Pi requests instance of Rj
  • Pi is holding an instance of Rj

Pi Rj

Pi R j

Resource Allocation Graph

Resource Allocation Graph w/ Deadlock

No Deadlock

Deadlock Prevention

Restrain the ways request can be made, such

that one of the 4 conditions (from earlier) cannot happen:

➊ Mutual Exclusion (mutex)

  • do not require mutex for sharable resources
    • (potential problems?);
  • must hold for nonsharable resources.

Deadlock Prevention

➋ Hold and Wait

  • whenever a process requests a resource, it does not hold any other resources. Can be done by requiring either:
  1. must request and be allocated all its resources before it begins execution, or
  2. allow requests only when the process has none.
  • low resource utilization; starvation possible.

Deadlock Prevention

➍ Circular Wait

  • impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration.

i.e. F(DVD Drive) = 1 F(disk drive) = 5 F(printer) = 12

If you have a resource, can only request resourcesDocsity.com