Slide 10-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10.

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Slide 10-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Operating Systems Lecture Notes Deadlocks Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
Deadlock Prevention, Avoidance, and Detection.  The Deadlock problem The Deadlock problem  Conditions for deadlocks Conditions for deadlocks  Graph-theoretic.
Chapter 7: Deadlocks.
Chapter 81 Deadlock is:  A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.  Example.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks.
© 2004, D. J. Foreman 1 Deadlock. © 2004, D. J. Foreman 2 Example  P1 requests most of real memory  Disk block mgr is swapped out ot make room for P1's.
Deadlocks CS 3100 Deadlocks1. The Deadlock Problem A set of blocked processes each holding a resource and waiting to acquire a resource held by another.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 8: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks.
10 Deadlock Example Process 1 Process 2 Resource 1 Resource 2 Process holds the resource Process requests the resource.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
Deadlock. Example Process 1 Process 2 Resource 1 Resource 2.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
Deadlocks Gordon College Stephen Brinton. Deadlock Overview The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks.
What we will cover…  The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 8: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Cosc 4740 Chapter 6, Part 4 Deadlocks. The Deadlock Problem A set of blocked processes each holding a resource and waiting to acquire a resource held.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-6 Deadlocks Department of Computer Science and Software Engineering.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 AE4B33OSS Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
CS6502 Operating Systems - Dr. J. Garrido Deadlock – Part 2 (Lecture 7a) CS5002 Operating Systems Dr. Jose M. Garrido.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
Dr. Kalpakis CMSC 421, Operating Systems Deadlocks.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks System Model Deadlock Characterization Methods.
Slide 10-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 7 Operating Systems.
Chapter 8 Deadlocks. Objective System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection.
Chapter 7: Deadlocks. 7.2CSCI 380 – Operating Systems Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization Methods for Handling.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
CS307 Operating Systems Deadlocks Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2012.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 6 Deadlocks Slide 1 Chapter 6 Deadlocks.
Ch 3 –What is a deadlock ? –Conditions Hold and Wait Mutual Exclusion Non Preemption Circular Wait –Deadlock Models Single Unit Request AND Request OR.
Deadlocks Introduction to Operating Systems: Module 7.
Deadlocks Copyright ©: University of Illinois CS 241 Staff1.
Slide 10-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10.
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 7: Deadlocks.
Outline Objective for today: Formal treatment of deadlock.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
7.1 CSE Department MAITSandeep Tayal 7: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
Lecture 6 Deadlock 1. Deadlock and Starvation Let S and Q be two semaphores initialized to 1 P 0 P 1 wait (S); wait (Q); wait (Q); wait (S);. signal (S);
2 Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process.
Chapter 7: Deadlocks. The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
OPERATING SYSTEM CONCEPTS AND PRACTISE
Process Management Deadlocks.
Chapter 7: Deadlocks.
Ch 3 What is a deadlock ? Conditions Deadlock Models Hold and Wait
Concurrency: Deadlock and Starvation
ITEC 202 Operating Systems
Chapter 7: Deadlocks.
Operating System: DEADLOCKS
Chapter 7 Deadlocks.
Process Deadlocks.
Outline Announcement Deadlock Deadlock definition - review
Outline Deadlocks, dead lock prevention, avoidance.
Deadlock Prevention Restrain the ways request can be made.
CSc 552 Advanced Unix Process deadlock deadlock prevention
Deadlock.
Deadlock.
Deadlock © 2004, D. J. Foreman.
Deadlock.
Deadlock.
Chapter 7: Deadlocks.
Presentation transcript:

Slide 10-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10

Slide 10-2 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter Deadlock

Slide 10-3 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Deadlock System Model Deadlock Characterization Methods for Handling Deadlocks –Deadlock Prevention –Deadlock Avoidance –Deadlock Detection & Recovery

Slide 10-4 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Example Process 1 Process 2 Resource 1 Resource 2 Process holds the resource Process requests the resource

Slide 10-5 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Three Deadlocked Processes Process 1 Process 2 Process 3 Resource 1 Resource 2 Resource 3 Process holds the resource Process requests the resource

Slide 10-6 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 A Model P = {p 1, p 2, …, p n } be a set of processes R = {R 1, R 2, …, R m } be a set of resources c j = number of units of R j in the system S = {S 0, S 1, …} be a set of states representing the assignment of R j to p i –State changes when processes take action –This allows us to identify a deadlock situation in the operating system

Slide 10-7 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 State Transitions The system changes state because of the action of some process, p i There are three pertinent actions: –Request (“r i ”): request one or more units of a resource –Allocation (“a i ”): All outstanding requests from a process for a given resource are satisfied –Deallocation (“d i ”): The process releases units of a resource SjSj SkSk xixi

Slide 10-8 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Properties of States Want to define deadlock in terms of patterns of transitions Define: p i is blocked in S j if p i cannot cause a transition out of S j SjSj r3r3 a1a1 r1r1 p 2 is blocked in S j

Slide 10-9 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Properties of States (cont) If p i is blocked in S j, and will also be blocked in every S k reachable from S j, then p i is deadlocked S j is called a deadlock state

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Example ra d S0S0 S1S1 S2S2 S3S3 S4S4 ra d One process, two units of one resource Can request one unit at a time

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Extension of Example r0r0 a0a0 d0d0 S 00 S 10 S 20 S 30 S 40 r0r0 a0a0 d0d0 r0r0 a0a0 d0d0 S 01 S 11 S 21 S 31 S 41 r0r0 a0a0 d0d0 r0r0 a0a0 d0d0 S 02 S 12 S 22 S 32 r0r0 r0r0 a0a0 d0d0 S 03 S 13 S 23 S 33 r0r0 S 04 S 14 r0r0 r1r1 r1r1 r1r1 r1r1 r1r1 r1r1 r1r1 r1r1 a1a1 a1a1 a1a1 a1a1 a1a1 a1a1 d1d1 d1d1 d1d1 d1d1 d1d1 d1d1 r1r1

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Resource Allocation Graph

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Resource Allocation Graph (cont.)

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 A Simple Process-Resource Model Instance P1P1 P1P1 P3P3 P3P3 P2P2 P2P2 R1R1 R1R1 R2R2 R2R2 R3R3 R3R3 Process holds resource Process requests resource

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Example of a graph with no cycles

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Example of a graph with a cycle

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Basic Facts

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Figure 10 ‑ 10: A Model of a State with a Circular Wait RP RP P holds R P requests R RiRi PiPi

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Dining Philosophers Revisited philosopher(int i){ while (TRUE) { // Think // Eat P(fork[i]); /* Pick up left fork */ P(fork[(i+1) mod 5]); /* Pick up right fork */ eat(); V(fork[(i+1) mod 5]); V(fork[i]); } philosopher4(){ while (TRUE) { // Think // Eat P(fork[0]); /* Pick up right fork */ P(fork[4]); /* Pick up left fork */ eat(); V(fork[4]); V(fork[0]); } semaphore fork[5]; fork[0] = fork[1] = fork[2] = fork[3] = fork[4] = 1; fork(philosopher, 1, 0); fork(philosopher, 1, 1); fork(philosopher, 1, 2); fork(philosopher, 1, 3); fork(philosopher4, 0);

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Addressing Deadlock Prevention: Design the system so that deadlock is impossible Avoidance: Construct a model of system states, then choose a strategy that will not allow the system to go to a deadlock state Detection & Recovery: Check for deadlock (periodically or sporadically), then recover Manual intervention: Have the operator reboot the machine if it seems too slow

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Prevention Necessary conditions for deadlock –Mutual exclusion –Hold and wait –Circular waiting –No preemption Ensure that at least one of the necessary conditions is false at all times –Mutual exclusion must hold at all times

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Hold and Wait Need to be sure a process does not hold one resource while requesting another Approach 1: Force a process to request all resources it needs at one time –Used in batch processing systems

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Hold and Wait Approach 2: If a process needs to acquire a new resource, it must first release all resources it holds, then reacquire all it needs –Used in interactive systems

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Circular Wait Have a situation in which there are K processes holding units of K resources RP RP P holds R P requests R RiRi PiPi

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Circular Wait (cont) There is a cycle in the graph of processes and resources Choose a resource request strategy by which no cycle will be introduced Total order on all resources, then can only ask for R j if R i < R j for all R i the process is currently holding This is how we noticed the easy solution for the dining philosophers

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Allowing Preemption Allow a process to time-out on a blocked request -- withdrawing the request if it fails SiSi ruru dvdv ruru SjSj SkSk wuwu

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Avoidance Define a model of system states, then choose a strategy that will guarantee that the system will not go to a deadlock state Requires extra information, e.g., the maximum claim for each process Allows resource manager to see the worst case that could happen, then to allow transitions based on that knowledge

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Safe vs Unsafe States Safe state: one in which the system can assure that any sequence of subsequent transitions leads back to the initial state –Even if all exercise their maximum claim, there is an allocation strategy by which all claims can be met Unsafe state: one in which the system cannot guarantee that the system will transition back to the initial state –Unsafe state can lead to a deadlock state if too many processes exercise their maximum claim at once

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 More on Safe & Unsafe States Normal Execution Request Max Claim Execute, then release No Yes Likely to be in a safe state Probability of being in unsafe state increases

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 More on Safe & Unsafe States I Safe States Unsafe States Deadlock States Disallow

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Basic Facts

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Banker's Algorithm

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Banker’s Algorithm Let maxc[i, j] be the maximum claim for R j by p i Let alloc[i, j] be the number of units of R j held by p i Can always compute –avail[j] = c j -  0  i  n alloc[i,j] –Then number of available units of R j Should be able to determine if the state is safe or not using this info

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Banker’s Algorithm Copy the alloc[i,j] table to alloc’[i,j] Given C, maxc and alloc’, compute avail vector Find p i : maxc[i,j] - alloc’[i,j]  avail[j] for 0  j < m and 0  i < n. –If no such p i exists, the state is unsafe –If alloc’[i,j] is 0 for all i and j, the state is safe Set alloc’[i,j] to 0; deallocate all resources held by p i ; go to Step 2

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Example ProcessR 0 R 1 R 2 R 3 p p p p p Maximum Claim ProcessR 0 R 1 R 2 R 3 p p p p p Sum7375 Allocated Resources C = Compute total allocated Determine available units avail = = Can anyone’s maxc be met? maxc[2,0]-alloc’[2,0] = 5-4 = 1  1 = avail[0] maxc[2,1]-alloc’[2,1] = 1-0 = 1  2 = avail[1] maxc[2,2]-alloc’[2,2] = 0-0 = 0  2 = avail[2] maxc[2,3]-alloc’[2,3] = 5-3 = 2  2 = avail[3] P 2 can exercise max claim avail[0] = avail[0]+alloc’[2,0] = 1+4 = 5 avail[1] = avail[1]+alloc’[2,1] = 2+0 = 2 avail[2] = avail[2]+alloc’[2,2] = 2+0 = 2 avail[3] = avail[3]+alloc’[2,3] = 2+3 = 5

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Example ProcessR 0 R 1 R 2 R 3 p p p p p Maximum Claim ProcessR 0 R 1 R 2 R 3 p p p p p Sum3372 Allocated Resources C = Compute total allocated Determine available units avail = = Can anyone’s maxc be met? maxc[4,0]-alloc’[4,0] = 5-1 = 4  5 = avail[0] maxc[4,1]-alloc’[4,1] = 0-0 = 0  2 = avail[1] maxc[4,2]-alloc’[4,2] = 3-3 = 0  2 = avail[2] maxc[4,3]-alloc’[4,3] = 3-0 = 3  5 = avail[3] P 4 can exercise max claim avail[0] = avail[0]+alloc’[4,0] = 5+1 = 6 avail[1] = avail[1]+alloc’[4,1] = 2+0 = 2 avail[2] = avail[2]+alloc’[4,2] = 2+3 = 5 avail[3] = avail[3]+alloc’[4,3] = 5+0 = 5

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Example ProcessR 0 R 1 R 2 R 3 p p p p p Maximum Claim ProcessR 0 R 1 R 2 R 3 p p p p p Sum2342 Allocated Resources C = Compute total allocated Determine available units avail = = Can anyone’s maxc be met? p 1 Can anyone’s maxc be met? (Yes, any of them can)

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Detection & Recovery Check for deadlock (periodically or sporadically), then recover Can be far more aggressive with allocation No maximum claim, no safe/unsafe states Differentiate between –Serially reusable resources: A unit must be allocated before being released –Consumable resources: Never release acquired resources; resource count is number currently available

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Reusable Resource Graphs (RRGs) Micro model to describe a single state Nodes = {p 0, p 1, …, p n }  {R 1, R 2, …, R m } Edges connect p i to R j, or R j to p i –(p i, R j ) is a request edge for one unit of R j –(R j, p i ) is an assignment edge of one unit of R j For each R j there is a count, c j of units Rj Number of units of R j allocated to p i plus the number requested by p i cannot exceed c j

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 State Transitions due to Request In S j, p i is allowed to request q  c h units of R h, provided p i has no outstanding requests. S j  S k, where the RRG for S k is derived from S j by adding q request edges from p i to R h RhRh pipi RhRh pipi State S j State S k p i request q units of R h q edges

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 State Transition for Acquire In S j, p i is allowed to acquire units of R h, iff there is (p i, R h ) in the graph, and all can be satisfied. S j  S k, where the RRG for S k is derived from S j by changing each request edge to an assignment edge. RhRh pipi RhRh pipi State S j State S k p i acquires units of R h

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 State Transition for Release In S j, p i is allowed to release units of R h, iff there is (R h, p i ) in the graph, and there is no request edge from p i. S j  S k, where the RRG for S k is derived from S j by deleting all assignment edges. RhRh pipi RhRh pipi State S j State S k p i releases units of R h

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Single Instance of Each Resource Type Maintain a resource allocation graph Periodically invoke algorithm that searches for cycles in the graph If there is a cycle ==> set of processes in cycle are in deadlock

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Example P holds one unit of R A Deadlock State P requests one unit of R R R p p

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Example Not a Deadlock StateNo Cycle in the Graph

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Example p0p0 p1p1 S 00

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Example p0p0 p1p1 p0p0 p1p1 S 00 S 01

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Example p0p0 p1p1 p0p0 p0p0 p1p1 p1p1 S 00 S 01 S 11

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Example p0p0 p1p1 p0p0 p0p0 p0p0 p1p1 p1p1 p1p1 S 00 S 01 S 11 S 21

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Example p0p0 p1p1 p0p0 p0p0 p0p0 p0p0 p1p1 p1p1 p1p1 p1p1 S 00 S 01 S 11 S 21 S 22

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Example p0p0 p1p1 p0p0 p0p0 p0p0 p0p0 p0p0 p1p1 p1p1 p1p1 p1p1 p1p1 S 00 S 01 S 11 S 21 S 22 S 33...

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Graph Reduction Deadlock state if there is no sequence of transitions unblocking every process A RRG represents a state; can analyze the RRG to determine if there is a sequence A graph reduction represents the (optimal) action of an unblocked process. Can reduce by p i if –p i is not blocked –p i has no request edges, and there are (R j, p i ) in the RRG

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Graph Reduction (cont) Transforms RRG to another RRG with all assignment edges into p i removed Represents p i releasing the resources it holds pipi pipi Reducing by p i

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Graph Reduction (cont) A RRG is completely reducible if there a sequence of reductions that leads to a RRG with no edges A state is a deadlock state if and only if the RRG is not completely reducible.

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Example RRG p0p0 p1p1 p2p2 p0p0 p1p1 p2p2 p0p0 p1p1 p2p2 p0p0 p1p1 p2p2

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Example RRG p0p0 p1p1 p2p2

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Consumable Resource Graphs (CRGs) Number of units varies, have producers/consumers Nodes = {p 0, p 1, …, p n }  {R 1, R 2, …, R m } Edges connect p i to R j, or R j to p i –(p i, R j ) is a request edge for one unit of R j –(R j, p i ) is an producer edge (must have at least one producer for each R j ) For each R j there is a count, w j of units R j

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 State Transitions due to Request In S j, p i is allowed to request any number of units of R h, provided p i has no outstanding requests. S j  S k, where the CRG for S k is derived from Sj by adding q request edges from p i to R h RhRh pipi RhRh pipi State S j State S k p i request q units of R h q edges

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 State Transition for Acquire In S j, p i is allowed to acquire units of R h, iff there is (p i, R h ) in the graph, and all can be satisfied. S j  S k, where the CRG for S k is derived from Sj by deleting each request edge and decrementing w h. RhRh pipi RhRh pipi State S j State S k p i acquires units of R h

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 State Transition for Release In S j, p i is allowed to release units of R h, iff there is (R h, p i ) in the graph, and there is no request edge from p i. S j  S k, where the CRG for S k is derived from S j by incrementing w h. RhRh pipi RhRh pipi State S j State S k p i releases 2 units of R h

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Example p0p0 p1p1 p0p0 p1p1 p0p0 p1p1 p0p0 p1p1 p0p0 p1p1

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Deadlock Detection May have a CRG that is not completely reducible, but it is not a deadlock state For each process: –Find at least one sequence which leaves each process unblocked. There may be different sequences for different processes -- not necessarily an efficient approach

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Deadlock Detection May have a CRG that is not completely reducible, but it is not a deadlock state Only need to find sequences, which leave each process unblocked. p0p0 p1p1

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Deadlock Detection May have a CRG that is not completely reducible, but it is not a deadlock state Only need to find a set of sequences, which leaves each process unblocked.

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 General Resource Graphs Have consumable and reusable resources Apply consumable reductions to consumables, and reusable reductions to reusables See Figure 10.29

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 GRG Example (Fig 10.29) Reusable Consumable p0p0 R2R2 R1R1 R0R0 p3p3 p2p2 p1p1 Not in Fig 10.29

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 GRG Example (Fig 10.29) Reusable Consumable p0p0 R2R2 R1R1 R0R0 p3p3 p2p2 p1p1 Reduce by p 3

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 GRG Example (Fig 10.29) Reusable Consumable p0p0 R2R2 R1R1 R0R0 p3p3 p2p2 p1p1 Reduce by p 0 

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Recovery No magic here –Choose a blocked process –Preempt it (releasing its resources) –Run the detection algorithm –Iterate it until the state is not a deadlock state

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Recovery From Deadlock

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10 Deadlock Detection-- Usage