Docsity

Deadlocks Two - Computer Operating Systems - Lecture Slides, Slides of Operating Systems

Partial preview of the text

Download Deadlocks Two - Computer Operating Systems - Lecture Slides and more Slides Operating Systems in PDF only on Docsity!

Lecture 14

Chapter 7: Deadlocks (cont)

Docsity.com

Chapter 7: Deadlocks

  • The Deadlock Problem
  • System Model
  • Deadlock Characterization
  • Methods for Handling Deadlocks
  • Deadlock Prevention
  • Deadlock Avoidance
  • Deadlock Detection
  • Recovery from Deadlock

Docsity.com

The Deadlock Problem

  • A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set
  • Example
    • System has 2 disk drives
    • P 1 and P 2 each hold one disk drive and each needs another one
  • Example
    • semaphores A and B , initialized to 1 P 0 P 1 wait (A); wait(B) wait (B); wait(A) Docsity.com

Bridge Crossing Example

  • Traffic only in one direction
  • Each section of a bridge can be viewed as a resource
  • If a deadlock occurs, it can be resolved if one car backs up - preempt resources and rollback Docsity.com

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
  • No preemption: a resource can be released only voluntarily by the process holding it, after that process has

Deadlock can arise if four conditions hold simultaneously.

necessary^ conditions

sufficient^ condition

Docsity.com

Resource-Allocation Graph

  • V is partitioned into two types:
    • P = { P 1 , P 2 , โ€ฆ, Pn }, the set consisting of all the processes in the system
    • R = { R 1 , R 2 , โ€ฆ, R (^) m }, the set consisting of all resource types in the system
  • request edge โ€“ directed edge P 1 โ†’ R (^) j
  • assignment edge โ€“ directed edge R โ†’ P

A set of vertices V and a set of edges E.

Docsity.com

Example of a Resource Allocation

Graph

Docsity.com

Basic Facts

  • If graph contains no cycles โ‡’ no deadlock
  • If graph contains a cycle โ‡’
    • if only one instance per resource type, then deadlock
    • if several instances per resource type, possibility of deadlock

Docsity.com

Methods for Handling Deadlocks

  • Ensure that the system will never enter a deadlock state - deadlock prevention - design decision - deadlock avoidance - runtime decision
  • Allow the system to enter a deadlock state and then recover - deadlock recovery - periodic runtime decision Docsity.com

Deadlock Prevention

  • Mutual Exclusion โ€“ not required for sharable resources; - must hold for nonsharable resources - not possible - must always be supported by the O/S
  • Hold and Wait โ€“ must guarantee that whenever a process requests a resource, it does not hold any other resources - Require process to request and be allocated all its resources before it begins execution,

Restrain the ways request can be made

Docsity.com

Deadlock Avoidance

  • Simplest and most useful model requires that each process declare the maximum number of resources of each type that it may need
  • The deadlock-avoidance algorithm dynamically examines the resource- allocation state to ensure that there can never be a circular-wait condition - mainly a scheduling problem

Requires that the system has some additional a priori information available

Docsity.com

Safe State

  • When a process requests an available resource, system must decide - if immediate allocation leaves the system in a safe state
  • System is in safe state if there exists a sequence < P 1 , P 2 , โ€ฆ, P (^) n > of ALL the processes is the systems such that - for each Pi , the resources that Pi can still request can be satisfied by currently available resources + resources held by all the Pj , with j < I
  • That is: Docsity.com

Avoidance algorithms

  • Single instance of a resource type
    • Use a resource-allocation graph
  • Multiple instances of a resource type
    • Use the bankerโ€™s algorithm

Docsity.com

Resource-Allocation Graph Scheme

  • Claim edge Pi โ†’ R (^) j indicated that process Pj may request resource R (^) j ; represented by a dashed line
  • Claim edge converts to request edge when a process requests a resource
  • Request edge converted to an assignment edge when the resource is allocated to the process Docsity.com