Dr. Kalpakis CMSC 621, Advanced Operating Systems. Fall 2003 URL: Basics of Deadlock Theory.

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Chapter 7: Deadlocks Adapted by Donghui Zhang from the original version by Silberschatz et al.
Distributed Deadlocks
Deadlock Prevention, Avoidance, and Detection
ICS Principles of Operating Systems Lectures 8 and 9 - Deadlocks Prof. Dmitri V. Kalashnikov dvk ics.uci.edu Slides © Prof. Nalini Venkatasubramanian.
Handling Deadlocks n definition, wait-for graphs n fundamental causes of deadlocks n resource allocation graphs and conditions for deadlock existence n.
Lecture 6 :Deadlocks. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate with each other Involves.
Deadlock Prevention, Avoidance, and Detection.  The Deadlock problem The Deadlock problem  Conditions for deadlocks Conditions for deadlocks  Graph-theoretic.
DEADLOCK. Contents  Principles of deadlock  Deadlock prevention  Deadlock detection.
7.5 Deadlock Avoidance The algorithm is simply to ensure that the system will always remain in safe state. Therefore, if a process requests a resource.
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.
Deadlocks. 2 System Model There are non-shared computer resources –Maybe more than one instance –Printers, Semaphores, Tape drives, CPU Processes need.
Chapter 7: Deadlocks. 7.2 Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks.
Deadlock CSCI 444/544 Operating Systems Fall 2008.
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.
What we will cover…  The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock.
Deadlock Characterization
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.
CS6502 Operating Systems - Dr. J. Garrido Deadlock – Part 2 (Lecture 7a) CS5002 Operating Systems Dr. Jose M. Garrido.
Dr. Kalpakis CMSC 421, Operating Systems Deadlocks.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 7 Operating Systems.
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 - System Model - Deadlock characterization - Methods for handling deadlocks - Deadlock prevention,avoidance - Deadlock detection and recovery.
Deadlock. Chapter 7: Deadlocks 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 Chapter 6: Deadlocks.
Deadlocks CPE Operating Systems
7: Deadlocks1 OPERATING SYSTEMS DEADLOCKS. 7: Deadlocks2 What Is In This Chapter? What is a deadlock? Staying Safe: Preventing and Avoiding Deadlocks.
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);
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.
Thursday, February 23, 2012 Chapter 6 homework questions?
Chapter 7: Deadlocks.
OPERATING SYSTEM CONCEPTS AND PRACTISE
Chapter 7: Deadlocks.
CSE 120 Principles of Operating
Ch 3 What is a deadlock ? Conditions Deadlock Models Hold and Wait
Concurrency: Deadlock and Starvation
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks.
Advanced Operating System Fall 2009
Operating System: DEADLOCKS
Lecture 19: Deadlock: Conditions, Detection and Avoidance
Chapter 7 Deadlocks.
Chapter 7: Deadlocks.
Process 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.
Deadlock B.Ramamurthy CSE421 1/11/2019 B.Ramamurthy.
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks.
Deadlocks Peng Lu In a multiprogramming environment, several processes may compete for a finite number of resources. A process requests resources; if the.
Deadlock B.Ramamurthy CSE421 2/23/2019 B.Ramamurthy.
Deadlocks Session - 13.
DEADLOCK.
Chapter 7: Deadlocks.
Lecture 19: Deadlock: Conditions, Detection and Avoidance
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.
Chapter 7: Deadlocks.
Chapter 8: Deadlocks Deadlock Characterization
Deadlock B.Ramamurthy CSE421 8/28/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 9/3/2019 B.Ramamurthy.
Presentation transcript:

Dr. Kalpakis CMSC 621, Advanced Operating Systems. Fall 2003 URL: Basics of Deadlock Theory

CMSC 621, Fall URL: Deadlocks deadlock occurs when there is a set of processes which have outstanding requests for resources that can never be satisfied starvation occurs when there are processes waiting for resources that become available and never get assigned to them the wait-for-graph (WFG) is a graph with nodes representing processes edges p --> q if process p waits for a resource held by process q in studying deadlocks both processes, resources, resource types and accesses, and types of requests need to be considered

CMSC 621, Fall URL: Necessary conditions for deadlocks Four general conditions are necessary for deadlock to occur exclusive access resources hold and wait no preemption circular wait these conditions are not sufficient

CMSC 621, Fall URL: Deadlock Handling Strategies prevention grant resource requests so that one of the necessary conditions does not hold detection & recovery examine resource allocation and pending requests and test for deadlock; if present, recover by aborting some deadlocked processes avoidance grant resource requests as long as the system remains in a safe state after resources are allocated

CMSC 621, Fall URL: Deadlock Models Single-unit requests AND-requests process requests multiple resources and stays blocked until all are satisfied cycles in WFG are sufficient for deadlock OR-requests process requests multiple resources and stays blocked until any one of them is satisfied cycles in WFG are not sufficient for deadlock; knots are AND-OR requests P-out-of-Q requests

CMSC 621, Fall URL: Resource Types & Accesses Reusable resources resource does not “change” when assigned/released to/by processes a resource allocated to one processes P can be allocated to another process after P releases that resource typical reusable resources: CPU, disk, etc Consumable resources resource changes (ceases to exist) after is assigned to a process typical consumable resources: messages, signals, semaphore operations Resources can be accessed in exclusive or shared mode

CMSC 621, Fall URL: Graph-Model for System State General resource system consists of a set of processes P1, P2, …, Pn a set of resources (reusable & consumable) R1, R2, …, Rm with ti available units for reusable resource Ri Qi, a set of producer processes for consumable resource Ri General resource graph G models system state bipartite graph with nodes the processes and resources an available units vector r=(r1, r2, …, rm) for all resources request edges: (P,R) if P requests 1 unit of R assignment edges: (R,P) if 1 unit of R (reusable) is assigned to P producer edges: (R,P) if P is producer of consumable R

CMSC 621, Fall URL: Example General Resource Graph P1 P2 R2 R1 request edge assignment edge producer edge consumable resource reusable resourceprocess

CMSC 621, Fall URL: General resource graph Must satisfy the following conditions for each reusable resource Ri total assigned units of Ri <= initial number of units of Ri available units of Ri = initial units of Ri - total assigned units of Ri for each process Pj assigned units of Ri to Pj+ requested units of Ri by Pj <= ri for each consumable resource the producer edges are proper available units >= 0 Process operations and effects on general resource graph request acquisition release

CMSC 621, Fall URL: Example graph P1 P2 R2 R1

CMSC 621, Fall URL: P1 requests two units of R1 P1 P2 R2 R1

CMSC 621, Fall URL: P1 acquires one unit of R2 P1 P2 R2 R1

CMSC 621, Fall URL: P2 acquires one unit of R1 P1 P2 R2 R1

CMSC 621, Fall URL: P2 releases three units of R2 P1 P2 R2 R1

CMSC 621, Fall URL: P2 releases one unit of R1 P1 P2 R2 R1

CMSC 621, Fall URL: Graph Reductions Reducing general resource graph G by an unblocked process Pi for each reusable resource delete all assignment and request edges for each assignment edge for a reusable resource increment the number of available units for that resource for each consumable resource delete all assignment, request, and producer edges set available units for that resource to infinity A process is blocked iff for some resource(s) the number of requested units is more than the available units of that resource

CMSC 621, Fall URL: Graph Reductions & Deadlocks G is completely reducible iff there exists a sequence of reductions that removes all edges from G Theorem. Pi is not deadlocked if there exists a sequence of reductions that takes the system in state where Pi is not blocked. Theorem. if G is completely reducible then G is deadlock free. Graph G is expedient if all processes with outstanding requests are blocked

CMSC 621, Fall URL: Cycles, Knots, & Deadlocks A knot in a graph G is a set K with at least two nodes such that the restriction of G to K is strongly connected there are no nodes in G-K reachable from K Useful fact: If a graph does not have a knot then there exists a path from every node to a sink node

CMSC 621, Fall URL: Cycles, Knots, & Deadlocks Theorem. In a general resource graph G a cycle is necessary for deadlocks a knot is sufficient for a deadlock provided G is expendient Prove it!! Theorem. For any process Pi in an expedient G, if there is no path from Pi to a sink then Pi belongs to a knot in G and Pi is deadlocked

CMSC 621, Fall URL: Knots are not necessary for deadlock

CMSC 621, Fall URL: Single-Unit Systems Consider a general resource graph G for a system where processes can request 1 unit of a resource at a time Theorem. If G is expedient then a knot is necessary and sufficient condition for a deadlock. a system with single-unit reusable resources only Theorem. If G is expedient then a cycle is necessary and sufficient for a deadlock. Efficient deadlock detection algorithms are possible

CMSC 621, Fall URL: System with only Reusable Resources Consider resource graph G Theorem. All reduction sequences applied to G result in the same state (graph) G’. Corollary. G is deadlock free if and only if G is completely reducible. Efficient deadlock detection algorithms are possible

CMSC 621, Fall URL: System with only Consumable Resources Theorem. If G’s claim-limited graph is completely reducible then G is deadlock-free Note that a system state may be deadlock free even though its claim-limited graph is not completely reducible

CMSC 621, Fall URL: System with only Consumable Resources Difficult to efficiently detect deadlocks a knot is not necessary for a deadlock to occur different reduction sequences lead into different states Can test whether a system is deadlock free using the claim-limited graph A general resource graph which corresponds to the worst-case system state the claim-limited graph for a system is constructed by making each consumable resource have zero available units having a request edge (P,R) iff P is a consumer of R

CMSC 621, Fall URL: Deadlock Prevention Methods Grant resource requests in such a wait such that one or more of the four necessary conditions for deadlock do not hold process begins only if all its requested resources can be granted blocked processes release resources they hold to other active (higher priority) processes requesting them processes request resources according to a resource priority ordering

CMSC 621, Fall URL: Deadlock Avoidance Assumption: Maximum resource requirements of all processes are known at all times A state is safe if there exists a serial process execution sequence where all processes complete Banker’s algorithm for deadlock avoidance

CMSC 621, Fall URL: Banker’s Algorithm Maintain A: maximum available units (row) vector B: maximum claim matrix one row vector Bi per process Pi denoting maximum resource units ever to be requested by Pi C: allocation matrix one row vector Ci per process Pi denoting resource units allocated to Pi D: available matrix D = A - sum(Ci, i=1..n) E: need matrix E = B - C

CMSC 621, Fall URL: Banker’s Algorithm Correctness conditions Bi <= A (claim units <= available units) C <= B (allocated units <= claim units) D >= 0 (total allocated units <= available units) Pi requests/releases resources with a vector Fi <= Ei if Pi releases resources Fi then D = D + Fi Ci = Ci - Fi Ei = Ei + Fi if Pi requests resources Fi then if Fi > D then block Pi else test safety of Fi and grant or deny its request depending on whether the resulting system state will be safe or not

CMSC 621, Fall URL: Testing Safety of a System State given a request Initially, label all processes unfinished Conditionally grant request Fi of Pi D = D - Fi Ci = Ci + Fi Ei = Ei - Fi While there exists an unfinished Pi such that Ei <= D do D = D + Ci label Pi as finished If all processes are labeled finished then state is safe and the request is granted else state is not safe undo all changes to D and process labels due to the while loop undo changes due to conditional granting of Fi deny request and block Pi

CMSC 621, Fall URL: Pros and Cons of Approaches Prevention (conservative) unnecessary pre-emptions, restricts concurrency, limits resource utilization avoidance (eager pessimistic) unnecessary denials, a priori knowledge of resource needs no process aborts detection (lazy optimistic) overhead for detection algorithm process aborts and rollbacks maximum concurrency, flexibility, no prior knowledge is needed

CMSC 621, Fall URL: Reading Chapter 3 of Singhal & Shivaratri R.C. Holt, “Some deadlock properties of computer systems”, ACM Computing Surveys, Sept. 1972, pp