Outline Objective for today: Formal treatment of deadlock.

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

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 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.
Operating Systems Principles Process Management and Coordination Lecture 6: Deadlocks 主講人:虞台文.
Chapter 7 Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks 7.1 System Model.
Lecture 7: Deadlocks, Deadlock Risk Management. Lecture 7 / Page 2AE4B33OSS Silberschatz, Galvin and Gagne ©2005 Contents The Concept of Deadlock Resource-Allocation.
Chapter 6 Concurrency: Deadlock and Starvation
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.
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.
10 Deadlock Example Process 1 Process 2 Resource 1 Resource 2 Process holds the resource Process requests the resource.
Deadlock CSCI 444/544 Operating Systems Fall 2008.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
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.
Concurrency: Deadlock and Starvation Chapter 6. Goal and approach Deadlock and starvation Underlying principles Solutions? –Prevention –Detection –Avoidance.
1 Concurrency: Deadlock and Starvation Chapter 6.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Objectives Understand the Deadlock.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Deadlocks.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
1 Deadlock. 2 Concurrency Issues Past lectures:  Problem: Safely coordinate access to shared resource  Solutions:  Use semaphores, monitors, locks,
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.
Chapter 7 Deadlocks Chapter 7: Deadlocks 7.1 System Model 7.2 Deadlock Characterization 7.3 Methods for Handling Deadlocks 7.4 Deadlock Prevention 7.5.
Lecture 12 Handling Deadlock – Prevention, avoidance and detection.
Mi-Jung Choi Dept. of Computer and Science Silberschatz, Galvin and Gagne ©2006 Operating System Principles Chapter 7: Deadlocks.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 7 Operating Systems.
CS307 Operating Systems Deadlocks Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2012.
1 Deadlock.  System Model  Process must request a resource before using  Process must release the resource when done  Deadlock  A set of processes.
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:=
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model 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.
Slide 10-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10.
CSE Operating System Principles Deadlocks. CSE – Operating System Principles2 Overview System Model Deadlock Characterization Methods for.
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);
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
Outline Objective for today: Formal treatment of deadlock. Bring Zax
Concurrency: Deadlock and Starvation
ICS Principles of Operating Systems
ITEC 202 Operating Systems
Chapter 7: Deadlocks.
Chapter 7 Deadlocks.
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.
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.
Chapter 7: Deadlocks.
Deadlock Hank Levy 1.
Operating Systems Principles Process Management and Coordination Lecture 6: Deadlocks 主講人:虞台文.
Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
Outline for today Objective: Administrative: Background on deadlock
Presentation transcript:

Outline Objective for today: Formal treatment of deadlock.

Deadlock Thread Lecture context switch = Timer interrupt goes off + Save current lecture state ( ESC out of current powerpoint slideshow) + Load state of other lecture (choose powerpoint window) + Reset timer + Run new lecture (Click on slideshow) The program counter

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 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 R i  P j means R i alloc to P j P j  R i means P j requests R i –Resource vertices contain units of the resource Resource R 0 Resource R 1 Process P 0 Process P 1 Request Arc Alloc Arc Reusable Resources

Deadlock Theory State transitions by operations: –Granting a request –Making a new request if all outstanding requests satisfied Deadlock defined on graph: –P i is blocked in state S if there is no operation P i can perform –P i 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) Resource R 0 Resource R 1 Process P 0 Process P 1 Request Arc Alloc Arc

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. R0R0 R1R1 P0P0 P1P1 Request Arc Alloc Arc P3P3

The Zax Deadlock Example Z0Z0 Z1Z1 B0B0 B1B1

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 P i from U; Cancel P i ’s outstanding requests; Release P i ’s allocated resources; /* possibly unblocking other P k in U */} if ( U != ) signal deadlock;

Deadlock Detection Example P0P0 R0R0 R2R2 R3R3 R4R4 R1R1 P3P3 P4P4 P2P2 P1P1

P0P0 R0R0 R2R2 R3R3 R4R4 R1R1 P3P3 P4P4 P2P2 P1P1

R0R0 R2R2 R3R3 R4R4 R1R1 P3P3 P4P4 P2P2 P0P0

R0R0 R2R2 R3R3 R4R4 R1R1 P3P3 P4P4 P2P2 P0P0

R0R0 R2R2 R3R3 R4R4 R1R1 P4P4 P2P2 P0P0

P0P0 R0R0 R2R2 R3R3 R4R4 R1R1 P4P4 P2P2

P0P0 R0R0 R2R2 R3R3 R4R4 R1R1 P4P4

P0P0 R0R0 R2R2 R3R3 R4R4 R1R1 P4P4

P0P0 R0R0 R2R2 R3R3 R4R4 R1R1

R0R0 R2R2 R3R3 R4R4 R1R1 Completely Reducible

Another Example R0R0 R1R1 P0P0 P1P1 Request Arc Alloc Arc P2P2 With and without P 2

Another Example R0R0 R1R1 P0P0 P1P1 Request Arc Alloc Arc With and without P 2 Is there an unblocked process to start with?

Another Example R0R0 R1R1 P0P0 P1P1 Request Arc Alloc Arc With and without P 2

Another Example R0R0 R1R1 P0P0 P1P1 Request Arc Alloc Arc With and without P 2

Another Example R0R0 R1R1 P0P0 P1P1 Request Arc Alloc Arc With and without P 2

Another Example R0R0 R1R1 P0P0 P1P1 Request Arc Alloc Arc P2P2 With and without P 2 Is there an unblocked process to start with?

Consumable Resources 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,  P0P0 P1P1 P2P2 Producer Arc Producer Arc R0R0 R1R1

Consumable Resources 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 P 2 P0P0 P1P1 P2P2 Producer Arc Producer Arc R0R0 R1R1

Consumable Resources 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 P 2 P0P0 P1P1 P2P2 Producer Arc Producer Arc R0R0 R1R1 Not reducible

Consumable Resources 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 P 2 P0P0 P1P1 P2P2 Producer Arc Producer Arc R0R0 R1R1

Consumable Resources 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 P 2 –Start with P 1 P0P0 P1P1 P2P2 Producer Arc Producer Arc R0R0 R1R1

Consumable Resources 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 P 1 P0P0 P1P1 P2P2 Producer Arc Producer Arc R0R0 R1R1 

Consumable Resources 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 P 1 P0P0 P1P1 P2P2 Producer Arc Producer Arc R0R0 R1R1  

Consumable Resources 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 P 1 P0P0 P1P1 P2P2 Producer Arc Producer Arc R0R0 R1R1 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[m] - avail[i] is the number of available units of R i max[n,m] - max[i,j] is claim of P i for R j alloc[n,m] - alloc[i,j] is current allocation of R j to P i need[n,m] = max[n,m] - alloc[n,m] - the rest that can be requested

Basic Outline of Algorithm 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 x request in ? if (x = = 1)? if (x = = 2)?

Basic Outline of Algorithm 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; request in ? if (x = = 1)?

Basic Outline of Algorithm 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; request in ?

Basic Outline of Algorithm 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; request in ?

Basic Outline of Algorithm 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; request in ? if (x = = 2)?