Outline Objective for today: Formal treatment of deadlock. Bring Zax

Slides:



Advertisements
Similar presentations
ICS Principles of Operating Systems Lectures 8 and 9 - Deadlocks Prof. Dmitri V. Kalashnikov dvk ics.uci.edu Slides © Prof. Nalini Venkatasubramanian.
Advertisements

Deadlock Prevention, Avoidance, and Detection.  The Deadlock problem The Deadlock problem  Conditions for deadlocks Conditions for deadlocks  Graph-theoretic.
Dr. Kalpakis CMSC 621, Advanced Operating Systems. Fall 2003 URL: Basics of Deadlock Theory.
6. Deadlocks 6.1 Deadlocks with Reusable and Consumable Resources
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.
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.
Deadlock CSCI 444/544 Operating Systems Fall 2008.
Deadlock. Example Process 1 Process 2 Resource 1 Resource 2.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
Deadlock Characterization
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Deadlocks.
System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention, Avoidance, and Detection Recovering from Deadlock Combined Approach.
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.
CS6502 Operating Systems - Dr. J. Garrido Deadlock – Part 2 (Lecture 7a) CS5002 Operating Systems Dr. Jose M. Garrido.
Chapter 8: Deadlocks Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection Recovery from Deadlock.
Dr. Kalpakis CMSC 421, Operating Systems Deadlocks.
Lecture 12 Handling Deadlock – Prevention, avoidance and detection.
Ch 3 –What is a deadlock ? –Conditions Hold and Wait Mutual Exclusion Non Preemption Circular Wait –Deadlock Models Single Unit Request AND Request OR.
Deadlock. Stepping on each other’s feet - I Thread T 1 b1:= allocate(); b2:= allocate(); …… release(b1); release(b2); Thread T 2 b1:= allocate(); b2:=
Outline Objective for today: Formal treatment of deadlock.
Deadlocks CPE Operating Systems
ICS Deadlocks 6.1 Deadlocks with Reusable and Consumable Resources 6.2 Approaches to the Deadlock Problem 6.3 A System Model –Resource Graphs –State.
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.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Thursday, February 23, 2012 Chapter 6 homework questions?
Chapter 7: Deadlocks.
OPERATING SYSTEM CONCEPTS AND PRACTISE
Process Management Deadlocks.
CSSE 332 Operating Systems Rose-Hulman Institute of Technology
Chapter 7: Deadlocks.
CSE 120 Principles of Operating
Ch 3 What is a deadlock ? Conditions Deadlock Models Hold and Wait
Concurrency: Deadlock and Starvation
ICS Principles of Operating Systems
Deadlock Management.
G.Anuradha Ref:- Galvin
Deadlock Permanent blocking of a set of process that compete for system resources or communicate with each other. Conditions that characterizes deadlock.
Chapter 7: Deadlocks Source & Copyright: Operating System Concepts, Silberschatz, Galvin and Gagne.
Chapter 7: Deadlocks.
Chapter 7 Deadlocks.
Process Deadlocks.
Outline Announcement Deadlock Deadlock definition - review
Deadlocks Definition A set of processes is in a Deadlock state when every process in the set is waiting for an event that can only be caused by another.
Deadlock B.Ramamurthy CSE421 1/11/2019 B.Ramamurthy.
Lecture 6: Deadlocks, Deadlock Risk Management
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks.
Outline Deadlocks, dead lock prevention, avoidance.
Deadlock Prevention Restrain the ways request can be made.
CSc 552 Advanced Unix Process deadlock deadlock prevention
Deadlocks Session - 14.
Deadlock B.Ramamurthy CSE421 2/23/2019 B.Ramamurthy.
DEADLOCK.
Chapter 7: Deadlocks.
Deadlock Hank Levy 1.
Deadlock B.Ramamurthy CSE421 4/23/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 5/1/2019 B.Ramamurthy.
CSCI 315 Operating Systems Design
Operating Systems Principles Process Management and Coordination Lecture 6: Deadlocks 主講人:虞台文.
Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 8/28/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 9/3/2019 B.Ramamurthy.
Outline for today Objective: Administrative: Background on deadlock
Presentation transcript:

Outline Objective for today: Formal treatment of deadlock. Bring Zax This lecture is too short for stand-alone. ADD SOMETHING

Dealing with Deadlock It can be prevented by breaking one of the prerequisite conditions (review): Mutually exclusive use of resources Example: Allowing shared access to read-only files (readers/writers problem from readers point of view) circular waiting Example: Define an ordering on resources and acquire them in order (lower numbered fork first) hold and wait no pre-emption

Dealing with Deadlock (cont.) Let it happen, then detect it and recover via externally-imposed preemption of resources Avoid dynamically by monitoring resource requests and denying some. Banker’s Algorithm ...

The Zax Deadlock Example

Deadlock Theory Resource R0 R1 Process P0 Process P1 Request Arc Alloc Arc State of resource allocation captured in Resource Graph Bipartite graph model with a set P of vertices representing processes and a set R for resources. Directed edges RiPj means Ri alloc to Pj PjRi means Pj requests Ri Resource vertices contain units of the resource Reusable Resources

Deadlock Theory State transitions by operations: Resource R0 R1 Process P0 Process P1 Request Arc Alloc Arc State transitions by operations: Granting a request Making a new request if all outstanding requests satisfied Deadlock defined on graph: Pi is blocked in state S if there is no operation Pi can perform Pi is deadlocked if it is blocked in all reachable states from S S is safe if no reachable state is a deadlock state (i.e., having some deadlocked process)

Deadlock Theory Cycle in graph is a necessary condition no cycle no deadlock. No deadlock iff graph is completely reducible Intuition: Analyze graph, asking if deadlock is inevitable from this state by simulating most favorable state transitions. Request Arc Alloc Arc R0 R1 P1 P3

The Zax Deadlock Example B0 B1

Deadlock Detection Algorithm Let U be the set of processes that have yet to be reduced. Initially U = P. Consider only reusable resources. while (there exist unblocked processes in U) { Remove unblocked Pi from U; Cancel Pi’s outstanding requests; Release Pi’s allocated resources; /* possibly unblocking other Pk in U */} if ( U != ) signal deadlock;

Deadlock Detection Example R2 R4 R0 R3 R1 P0 P3 P4

Deadlock Detection Example R2 R4 R0 R3 R1 P0 P3 P4

Deadlock Detection Example R2 R4 R0 R3 R1 P0 P3 P4

Deadlock Detection Example R2 R4 R0 R3 R1 P0 P3 P4

Deadlock Detection Example R2 R4 R0 R3 R1 P0 P4

Deadlock Detection Example R2 R4 R0 R3 R1 P0 P4

Deadlock Detection Example R2 R4 R0 R3 R1 P0 P4

Deadlock Detection Example R2 R4 R0 R3 R1 P0 P4

Deadlock Detection Example R2 R4 R0 R3 R1 P0

Deadlock Detection Example R2 R4 R0 R3 R1 Completely Reducible

Another Example P0 Request Alloc Arc Arc R0 R1 P1 With and without P2

Another Example P0 Request Alloc Arc Arc R0 R1 P1 Is there an unblocked process to start with? With and without P2

Another Example P0 Request Arc Alloc Arc R0 R1 P1 With and without P2

Another Example P0 Request Arc Alloc Arc R0 R1 P1 With and without P2

Another Example P0 Request Arc Alloc Arc R0 R1 P1 With and without P2

Another Example P0 Request Alloc Arc Arc R0 R1 Is there an unblocked process to start with? P1 With and without P2 P2

Consumable Resources P0 P1 P2 Producer Arc R0 R1 Not a fixed number of units, operations of producing and consuming (e.g. messages) Ordering matters on applying reductions Reducing by producer makes “enough” units, 

Consumable Resources R0 Producer Arc Not a fixed number of units, operations of producing and consuming (e.g. messages) Ordering matters on applying reductions Reducing by producer makes “enough” units,  Start with P2 P0 P1 Producer Arc P2 R1

Consumable Resources R0 Producer Arc Not a fixed number of units, operations of producing and consuming (e.g. messages) Ordering matters on applying reductions Reducing by producer makes “enough” units,  Start with P2 P0 P1 Producer Arc P2 R1 Not reducible

Consumable Resources P0 P1 P2 Producer Arc R0 R1 Not a fixed number of units, operations of producing and consuming (e.g. messages) Ordering matters on applying reductions Reducing by producer makes “enough” units,  Start with P2

Consumable Resources R0 Producer Arc Not a fixed number of units, operations of producing and consuming (e.g. messages) Ordering matters on applying reductions Reducing by producer makes “enough” units,  Start with P2 Start with P1 P0 P1 Producer Arc P2 R1

Consumable Resources R0 Producer Arc Not a fixed number of units, operations of producing and consuming (e.g. messages) Ordering matters on applying reductions Reducing by producer makes “enough” units,  Start with P1 P0  P1 Producer Arc P2 R1

Consumable Resources R0 Producer Arc Not a fixed number of units, operations of producing and consuming (e.g. messages) Ordering matters on applying reductions Reducing by producer makes “enough” units,  Start with P1 P0  P1 Producer Arc P2  R1

Consumable Resources R0 Producer Arc Not a fixed number of units, operations of producing and consuming (e.g. messages) Ordering matters on applying reductions Reducing by producer makes “enough” units,  Start with P1 P0 P1 Producer Arc P2 R1 Reducible

Deadlock Detection & Recovery Continuous monitoring and running this algorithm are expensive. What to do when a deadlock is detected? Abort deadlocked processes (will result in restarts). Preempt resources from selected processes, rolling back the victims to a previous state (undoing effects of work that has been done) Watch out for starvation.

Avoidance - Banker’s Algorithm Each process must declare its maximum claim on each of the resources and may never request beyond that level. When a process places a request, the Banker decides whether to grant that request according to the following criteria: “If I grant this request, then there is a run on the bank (everyone requests the remainder of their maximum claim), will we have deadlock?”

Representing the State n processes, m resources avail[m] - avail[i] is the number of available units of Ri max[n,m] - max[i,j] is claim of Pi for Rj alloc[n,m] - alloc[i,j] is current allocation of Rj to Pi need[n,m] = max[n,m] - alloc[n,m] - the rest that can be requested. 4 7 2 5 2 2

Basic Outline of Algorithm request in ? if (request[i,j] > avail[j]) defer; //Sufficient resources for request //pretend to grant request avail[j] = avail [j] - request [i,j]; alloc[i,j] = alloc[i,j] + request [i,j]; need[i,j] = need[i,j] - request [i,j]; if (safe state) grant; else defer; 4 7-x 2 5 x 2 2 if (x = = 1)? if (x = = 2)?

Basic Outline of Algorithm request in ? if (request[i,j] > avail[j]) defer; //Sufficient resources for request //pretend to grant request avail[j] = avail [j] - request [i,j]; alloc[i,j] = alloc[i,j] + request [i,j]; need[i,j] = need[i,j] - request [i,j]; if (safe state) grant; else defer; 4 6 2 5 1 2 2 if (x = = 1)?

Basic Outline of Algorithm request in ? if (request[i,j] > avail[j]) defer; //Sufficient resources for request //pretend to grant request avail[j] = avail [j] - request [i,j]; alloc[i,j] = alloc[i,j] + request [i,j]; need[i,j] = need[i,j] - request [i,j]; if (safe state) grant; else defer; 4 6 2 5 1

Basic Outline of Algorithm request in ? if (request[i,j] > avail[j]) defer; //Sufficient resources for request //pretend to grant request avail[j] = avail [j] - request [i,j]; alloc[i,j] = alloc[i,j] + request [i,j]; need[i,j] = need[i,j] - request [i,j]; if (safe state) grant; else defer; 6 2 1

Basic Outline of Algorithm request in ? if (request[i,j] > avail[j]) defer; //Sufficient resources for request //pretend to grant request avail[j] = avail [j] - request [i,j]; alloc[i,j] = alloc[i,j] + request [i,j]; need[i,j] = need[i,j] - request [i,j]; if (safe state) grant; else defer; 4 5 2 5 2 2 2 if (x = = 2)?