Deadlock 2.

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks.
Chapter 7: Deadlocks (Continuation). 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 30 Handling Deadlock.
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.
1 Wednesday, June 28, 2006 Command, n.: Statement presented by a human and accepted by a computer in such a manner as to make the human feel that he is.
Chapter 7. Deadlocks.
1 Chapter 7: Deadlock. 2 The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
03/07/2007CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
02/19/2008CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
03/03/2004CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Deadlocks Gordon College Stephen Brinton. Deadlock Overview The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks.
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 Chapter 7: Deadlocks.
What we will cover…  The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Deadlocks.
Chapter 7: Deadlocks Adapted to COP4610 by Robert van Engelen.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks Modified.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Chapter 7 Deadlocks. 7.2 Modified By Dr. Khaled Wassif Operating System Concepts – 7 th Edition Silberschatz, Galvin and Gagne ©2005 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.
CHAPTER 8: DEADLOCKS System Model Deadlock Characterization
 The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock Avoidance  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.
Lecture 12 Handling Deadlock – Prevention, avoidance and detection.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
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.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization.
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.
Chap 7 Deadlocks. Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks To.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 6 Deadlocks Slide 1 Chapter 6 Deadlocks.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 7: Deadlocks.
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.
CSE Operating System Principles Deadlocks. CSE – Operating System Principles2 Overview System Model Deadlock Characterization Methods for.
Deadlock. Examples You can't get a job without experience; you can't get experience without a job. A set of blocked processes each holding a resource.
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
CSSE 332 Operating Systems Rose-Hulman Institute of Technology
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 1/11/2019 B.Ramamurthy.
Outline Deadlocks, dead lock prevention, avoidance.
Deadlock Prevention Restrain the ways request can be made.
Deadlocks Session - 14.
Lecture 28 Syed Mansoor Sarwar
Deadlock B.Ramamurthy CSE421 2/23/2019 B.Ramamurthy.
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 4/23/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 5/1/2019 B.Ramamurthy.
CSCI 315 Operating Systems Design
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 8/28/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 9/3/2019 B.Ramamurthy.
Presentation transcript:

Deadlock 2

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 a safe state if there exists a safe sequence of all processes Sequence <P0, P1, …, Pn> is safe if 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 If Pi‘s resource needs are not immediately available, then Pi can wait until all Pj have finished When Pj finishes, Pi can obtain needed resources, execute, return allocated resources, and terminate When Pi terminates, Pi+1 can obtain its needed resources, and so on

Basic Facts If system is in safe state  no deadlock If system is in unsafe state  possibility of deadlock Avoidance  ensure that system will never enter an unsafe state

Safe, Unsafe, Deadlock State

Example Allocation Max Assume the system has 12 instances of the particular resource Is the system currently in a safe or in an unsafe state?

Example Suppose that P2 requests and is allocated one more instance of the resource, still assume the system has 12 instances of the resource Allocation Max P0 5 10 P1 2 4 P2 3 9 Is the system currently in a safe or in an unsafe state?

Deadlock Avoidance Requires that the system has some additional a priori information available: 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 Resource-allocation state is defined by the number of available and allocated resources, and the maximum demands of the processes

Avoidance algorithms Single instance of a resource type Use a resource-allocation graph Multiple instances of a resource type Use the banker’s algorithm

Resource-Allocation Graph Algorithm Can be used if we have a resource-allocation system with only one instance of each resource type. We just need ensure that no cycle exists Claim edge Pi  Rj indicates that process Pi may request resource Rj; represented by a dashed line Claim edge converts to request edge when a process requests a resource Resources must be claimed a priori in the system

Resource-Allocation Graph For Deadlock Avoidance Suppose P2 requests R2, can this request be granted?

Resource-Allocation Graph For Deadlock Avoidance

Resource-Allocation Graph Algorithm Suppose that process Pi requests a resource Rj The request can be granted only if converting the request edge to an assignment edge does not result in the formation of a cycle in the resource allocation graph

Banker’s Algorithm Multiple instances Each process must a priori claim maximum use When a process requests a resource it may have to wait When a process gets all its resources it must return them in a finite amount of time

Banker’s Algorithm Toward right idea: State maximum resource needs in advance Allow particular process to proceed if: (available resources - #requested)  max remaining that might be needed by any process Banker’s algorithm (less conservative): Allocate resources dynamically Evaluate each request and grant if some ordering of processes is still deadlock free afterward Technique: pretend request is granted, and check to see if resulting state would be a SAFE state. Grant request if result is deadlock free (conservative!) Keeps system in a SAFE state (i.e., there is always a safe sequence) Algorithm allows the sum of maximum resource needs of all current processes to be greater than total resources

Banker’s Algorithm: Example 5 processes P0 through P4; 3 resource types R0 (10 instances), R1 (5 instances), and R2 (7 instances) Snapshot at initial time: Allocation Max Available R0 R1 R2 R0 R1 R2 R0 R1 R2 P0 0 1 0 7 5 3 3 3 2 P1 2 0 0 3 2 2 P2 3 0 2 9 0 2 P3 2 1 1 2 2 2 P4 0 0 2 4 3 3 Is the system in a safe state? The system is in a safe state since the sequence <P1, P3, P4, P2, P0> satisfies safety criteria Need R0 R1 R2 7 4 3 1 2 2 6 0 0 0 1 1 4 3 1

Banker’s Algorithm: Example Suppose that P1 requests (1, 0, 2). Is it safe to honor this request? Allocation Max Available R0 R1 R2 R0 R1 R2 R0 R1 R2 P0 0 1 0 7 5 3 3 3 2 P1 2 0 0 3 2 2 P2 3 0 2 9 0 2 P3 2 1 1 2 2 2 P4 0 0 2 4 3 3 Find the new state that the system would be in if this request is granted. If the new state is safe, then it is safe to grant this request. Otherwise, it is not safe to honor this request (safety algorithm)

Banker’s Algorithm: Example This is the new state that the system would be in if P1’s request is honored Allocation Max Available R0 R1 R2 R0 R1 R2 R0 R1 R2 P0 0 1 0 7 5 3 2 3 0 P1 3 0 2 3 2 2 P2 3 0 2 9 0 2 P3 2 1 1 2 2 2 P4 0 0 2 4 3 3 The sequence <P1, P3, P4, P0, P2> satisfies safety requirement, so it is safe to honor P1’s request Can request for (3,3,0) by P4 be granted? Can request for (0,2,0) by P0 be granted?

Data Structures for the Banker’s Algorithm Let n be the number of processes, and m be the number of resource types Available: Vector of length m. If Available[j]= k, there are k instances of resource type Rj available Max: n x m matrix. If Max[i,j]= k, then process Pi may request at most k instances of resource type Rj Allocation: n x m matrix. If Allocation[i,j]= k then Pi is currently allocated k instances of Rj Need: n x m matrix. If Need[i,j]= k, then Pi may need k more instances of Rj to complete its task Need[i, j] = Max[i, j] – Allocation[i, j]

Resource-Request Algorithm for Process Pi Let Request be the request vector for process Pi. If Requesti[j] = k then process Pi wants k instances of resource type Rj 1. If Requesti  Needi go to step 2. Otherwise, raise error condition, since process has exceeded its maximum claim 2. If Requesti  Available, go to step 3. Otherwise Pi must wait, since resources are not available Pretend to allocate requested resources to Pi by modifying the state as follows: Available = Available - Requesti Allocationi = Allocationi + Requesti Needi = Needi – Requesti If safe  the resources are allocated to Pi If unsafe  Pi must wait, and the old resource-allocation state is restored

Safety Algorithm 1. Let Work and Finish be vectors of length m and n, respectively. Initialize: Work = Available Finish[i] = false for i = 0, 1, …, n 2. Find an i such that Finish[i] = false AND Needi  Work If no such i exists, go to step 4 3. Work = Work + Allocationi Finish[i] = true go to step 2 4. If Finish[i] == true for all i, then the system is in a safe state

Example Consider a computer system having 4 serially-reusable resource classes R0 (4 instances), R1 (3 instances), R2 (11 instances), and R3 (2 instances). There are 4 processes in the system P0 through P3. Assume that the maximum claim approach to deadlock avoidance is used. The current state is given by: Allocation Max R0 R1 R2 R3 R0 R1 R2 R3 P0 2 1 2 0 3 1 5 1 P1 1 0 4 1 2 2 6 2 P2 0 1 1 0 1 2 1 0 P3 0 0 3 0 1 1 7 1 Which of the following outstanding requests can be safely satisfied? Request R0 R1 R2 R3 P0 1 0 2 1 P1 0 1 0 1 P2 1 0 0 0 P3 0 0 1 1