We think you have liked this presentation. If you wish to download it, please recommend it to your friends in any social system. Share buttons are a little bit lower. Thank you!
Presentation is loading. Please wait.
Published bySarah Guthrie
Modified over 3 years ago
Chapter 8 Deadlocks Copyright © 2008
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.2Operating Systems, by Dhananjay Dhamdhere2 Introduction What is a Deadlock? Deadlocks in Resource Allocation Handling Deadlocks Deadlock Detection and Resolution Deadlock Prevention Deadlock Avoidance Characterization of Resource Deadlocks by Graph Models Deadlock Handling in Practice
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.3Operating Systems, by Dhananjay Dhamdhere3 What is a Deadlock? –Resource deadlock primary concern of OS P i, P j are deadlocked after their second requests –Deadlocks can also arise in synchronization and message communication user concern
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.4Operating Systems, by Dhananjay Dhamdhere4 Deadlocks in Resource Allocation OS may contain several resources of a kind –Resource unit refers to a resource of a specific kind –Resource class to refers to the collection of all resource units of a kind Resource allocation in a system entails three kinds of events: –Request for the resource –Actual allocation of the resource –Release of the resource Released resource can be allocated to another process
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.5Operating Systems, by Dhananjay Dhamdhere5 Deadlocks in Resource Allocation (continued)
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.6Operating Systems, by Dhananjay Dhamdhere6 Conditions for a Resource Deadlock Another condition is also essential for deadlocks: –No withdrawal of resource requests: A process blocked on a resource request cannot withdraw it
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.7Operating Systems, by Dhananjay Dhamdhere7 Modeling the Resource Allocation State (Resource) allocation state: –Information about resources allocated to processes and about pending resource requests –Used to determine whether a set of processes is deadlocked Two kinds of models are used to represent the allocation state of a system: –A graph model –A matrix model
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.8 Resource request and allocation graph (RRAG) Nodes and edges in an RRAG –Two kinds of nodes exist in an RRAG A circle is a process A rectangle is a resource class –Each bullet in a rectangle is one resource unit –Edges can also be of two kinds An edge from a resource class to a process is a resource allocation An edge from a process to a resource class is a pending resource request Operating Systems, by Dhananjay Dhamdhere8
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.9 Wait-for graph (WFG) A WFG can be used to depict the resource state of a system in which every resource class contains only one resource unit –A Node in the graph is a process –An edge is a wait-for relationship between processes A wait-for edge (P i, P j ) indicates that –Process P j holds the resource unit of a resource class –Process P i has requested the resource and it has become blocked on it –In essence P i waits for P j to release the resource Operating Systems, by Dhananjay Dhamdhere9
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.10Operating Systems, by Dhananjay Dhamdhere10 Graph Models
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.11 Paths in WFG and RRAG A path in a graph is a sequence of edges such that the destination node of an edge is the source node of the subsequent edge –Consider an RRAG path P 1 – R 1 – P 2 – R 2 … P n-1 – R n-1 – P n This path indicates that Process P n has been allocated a resource unit of R n-1 Process P n-1 has been allocated a resource unit of R n-2 and awaits a resource unit of R n-1, etc. –In WFG, the same path would be P 1 – P 2 – … P n-1 – P n Operating Systems, by Dhananjay Dhamdhere11
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.12Operating Systems, by Dhananjay Dhamdhere12 Graph Models (continued) A deadlock cannot exist unless an RRAG, or a WFG, contains a cycle A cycle in an RRAG does not necessarily imply a deadlock if a resource class has multiple resource units When P k completes, its tape unit can be allocated to P j
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.13Operating Systems, by Dhananjay Dhamdhere13 Matrix Model Allocation state represented by two matrices: –Allocated_resources –Requested_resources If system has n processes and r resource classes, each of these matrices is an n × r matrix Auxiliary: Total_resources and Free_resources
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.14Operating Systems, by Dhananjay Dhamdhere14 Handling Deadlocks
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.15Operating Systems, by Dhananjay Dhamdhere15 Deadlock Detection and Resolution A blocked process is not currently involved in a deadlock if request on which it is blocked can be satisfied through a sequence of process completion, resource release, and resource allocation events –If each resource class in system contains a single resource unit, check for a cycle in RRAG or WFG Not applicable if resource classes have multiple resource units –We will use matrix model Applicable in all situations
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.16Operating Systems, by Dhananjay Dhamdhere16 Example: Deadlock Detection The allocation state of a system containing 10 units of a resource class R 1 and three processes: Process P 3 is in the running state –We simulate its completion Allocate its resources to P 2 –All processes can complete in this manner No blocked processes exist when the simulation ends –Hence no deadlock
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.17Operating Systems, by Dhananjay Dhamdhere17 A Deadlock Detection Algorithm
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.18Operating Systems, by Dhananjay Dhamdhere18 Example: Operation of a Deadlock Detection Algorithm
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.19Operating Systems, by Dhananjay Dhamdhere19 Deadlock Resolution Deadlock resolution for a set of deadlocked processes D is breaking of deadlock to ensure progress for some processes in D –Achieved by aborting one or more processes in D Each aborted process is called a victim –Choice of victim made using criteria such as process priority, resources consumed by it, etc.
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.20Operating Systems, by Dhananjay Dhamdhere20 Deadlock Prevention
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.21Operating Systems, by Dhananjay Dhamdhere21 All Resources Together Simplest of all deadlock prevention policies Process must ask for all resources it needs in a single request –Kernel allocates all of them together A blocked process does not hold any resources –Hold-and-wait condition is never satisfied Attractive policy for small operating systems Has one practical drawback: –Adversely influences resource efficiency
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.22Operating Systems, by Dhananjay Dhamdhere22 Resource Ranking Resource rank associated with each resource class Upon resource request, kernel applies a validity constraint to decide if it should be considered –Rank of requested resource must be larger than rank of highest ranked resource allocated to the process Result: absence of circular wait-for relationships Works best when all processes require their resources in the order of increasing resource rank –In worst case, policy may degenerate into the all resources together policy of resource allocation
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.23Operating Systems, by Dhananjay Dhamdhere23 Deadlock Avoidance Bankers algorithm –Analogy: bankers admit loans that collectively exceed the banks funds and then release each borrowers loan in installments –Uses notion of a safe allocation state When system is in such a state, all processes can complete their operation without possibility of a deadlock –Deadlock avoidance implemented by taking system from one safe allocation state to another
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.24Operating Systems, by Dhananjay Dhamdhere24 Deadlock Avoidance
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.25Operating Systems, by Dhananjay Dhamdhere25 Deadlock Avoidance (continued) Outline of the approach: 1. When a process makes a request, compute projected allocation state – This would be the state if the request is granted 2. If projected allocation state is safe, grant request by updating Allocated_resources and Total_alloc; otherwise, keep request pending – Safety is checked through simulation – A process is assumed to complete only if it can get its maximum requirement of each resource satisfied simultaneously 3. When a process releases any resource(s) or completes its operation, examine pending requests and allocate those that would put the system in a new safe allocation state
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.26Operating Systems, by Dhananjay Dhamdhere26 Example: Bankers Algorithm for a Single Resource Class Now consider the following requests: 1.P 1 makes a request for 2 resource units 2.P 2 makes a request for 2 resource units 3.P 3 makes a request for 2 resource units –Requests by P 1 and P 2 do not put the system in safe allocation states, hence they will not be granted –Request by P 3 will be granted
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.27Operating Systems, by Dhananjay Dhamdhere27
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.28Operating Systems, by Dhananjay Dhamdhere28
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.29Operating Systems, by Dhananjay Dhamdhere29 Example: Bankers Algorithm for Multiple Resource Classes
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.30Operating Systems, by Dhananjay Dhamdhere30
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.31Operating Systems, by Dhananjay Dhamdhere31 Characterization of Resource Deadlocks by Graph Models A deadlock characterization is a statement of the essential features of a deadlock –We discuss characterization using graph models of allocation state and elements of graph theory A cycle in a RRAG or WFG is a sufficient condition for a deadlock in some systems, but not in others
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.32Operating Systems, by Dhananjay Dhamdhere32 Single-Instance, Single-Request (SISR) Systems Each resource class contains a single instance of the resource and each request is a single request A cycle in an RRAG implies a mutual wait-for relationship for a set of processes –Since each resource class contains a single resource unit Each blocked process P i in cycle waits for exactly one other process, say P k, to release required resource Hence a cycle that involves P i also involves P k A cycle is thus a necessary and sufficient condition to conclude that a deadlock exists in the system
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.33 A knot in RRAG is a necessary and sufficient condition for the existence of a deadlock in an MISR system Operating Systems, by Dhananjay Dhamdhere33 Multiple-Instance, Single-Request (MISR) Systems
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.34Operating Systems, by Dhananjay Dhamdhere34 Single-Instance, Multiple-Request (SIMR) Systems A process making a multiple request has > 1 out-edge –It remains blocked until each of the requested resources is available –A cycle is a necessary and sufficient condition for a deadlock in an SIMR system
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.35Operating Systems, by Dhananjay Dhamdhere35 Multiple-Instance, Multiple-Request (MIMR) Systems We must differentiate between process and resource nodes in the RRAG of an MIMR system –All out-edges of a resource node must be involved in cycles for a deadlock to arise –A process node needs to have only one out-edge involved in a cycle A resource knot incorporates these conditions
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.36Operating Systems, by Dhananjay Dhamdhere36 Multiple-Instance, Multiple-Request (MIMR) Systems (continued) A resource knot is a necessary and sufficient condition for the existence of a deadlock in an MIMR system... –And, in all classes of systems discussed in this section
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.37Operating Systems, by Dhananjay Dhamdhere37 Processes in Deadlock
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.38Operating Systems, by Dhananjay Dhamdhere38 Deadlock Handling in Practice Deadlock detection-and-resolution and deadlock avoidance are unattractive in practice (overhead) –OS uses deadlock prevention approach or simply does not care about possibility of deadlocks OSs tend to handle deadlock issues separately for each kind of resource –Memory: Explicit deadlock handling is unnecessary –I/O devices: Resources are not limited (virtual devices) –Files: Deadlocks are handled by processes, not OS –Control blocks: Resource ranking or all-resources-together
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.39Operating Systems, by Dhananjay Dhamdhere39 Deadlock Handling in Unix Most operating systems simply ignore the possibility of deadlocks involving user processes –Unix is no exception Unix addresses deadlocks due to sharing of kernel data structures by user processes –Kernel uses resource ranking (deadlock prevention) by requiring processes to set locks on kernel data structures in a standard order There are exceptions to this rule; deadlocks can arise –Special deadlock handling for buffer cache and file system
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.40Operating Systems, by Dhananjay Dhamdhere40 Deadlock Handling in Windows Vista has feature called wait chain traversal (WCT) –Assists applications and debuggers in detecting deadlocks –A wait chain starts on a thread and is analogous to a path in the RRAG Debugger can investigate cause of a freeze by invoking getthreadwaitchain with the id of a thread to retrieve a chain starting on that thread
Operating Systems, by Dhananjay Dhamdhere Copyright © 20088.41Operating Systems, by Dhananjay Dhamdhere41 Summary Deadlock: set of processes wait indefinitely for events because each of the events can be caused only by other processes in the set Resource deadlock arises when: –Resources are nonshareable and nonpreemptible –Hold-and-wait –Circular wait exists OS can discover a deadlock by analyzing the allocation state of a system –Use RRAG, WFG or matrix model Deadlocks can be detected, prevented and avoided
1 Concurrency: Deadlock and Starvation Chapter 6.
Time for a BREAK! You have 45 Minutes. Time Left 44.
PSSA Preparation. Question 1(no calculator) D Question 2 (no calculator)
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Chapter 11 Membrane Structure Essential Cell Biology Third Edition Copyright © Garland Science 2010.
C Copyright © 2005, Oracle. All rights reserved. Practice Solutions.
Chapter 10 Analyzing Genes and Genomes Essential Cell Biology Third Edition Copyright © Garland Science 2010.
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Chapter 7: Deadlocks.
Chapter 14 Energy Generation in Mitochondria and Chlorplasts Essential Cell Biology Third Edition Copyright © Garland Science 2010.
Chapter 12 Membrane Transport Essential Cell Biology Third Edition Copyright © Garland Science 2010.
Chapter 1 Introduction Copyright © Operating Systems, by Dhananjay Dhamdhere Copyright © Introduction Abstract Views of an Operating System.
Peterson’s Practice AP Exam
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 2 Author: Julia Richards and R. Scott Hawley.
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
and 5. and and
1 File Systems Chapter Files 6.2 Directories 6.3 File system implementation 6.4 Example file systems.
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
Prof. Valter Bezerra Dantas
Chapter 11 Memory Management Copyright © Operating Systems, by Dhananjay Dhamdhere Copyright © Operating Systems, by Dhananjay Dhamdhere2.
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
BMU - E I 1 Development of renewable energy sources in Germany in
Chapter 8 Deadlocks. Objective System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection.
Chapter 15 Intracellular Compartments and Transport Essential Cell Biology Third Edition Copyright © Garland Science 2010.
Immunobiology: The Immune System in Health & Disease Sixth Edition Chapter 13 Autoimmunity and Transplantation Copyright © 2005 by Garland Science Publishing.
ICS Principles of Operating Systems Lectures 8 and 9 - Deadlocks Prof. Dmitri V. Kalashnikov dvk ics.uci.edu Slides © Prof. Nalini Venkatasubramanian.
PP Test Review Sections 6-1 to 6-6 Mrs. Rivas 1. 2.
Chapter 7: Deadlocks Adapted by Donghui Zhang from the original version by Silberschatz et al.
Dr. Kalpakis CMSC 421, Operating Systems Deadlocks.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
UNITED NATIONS Shipment Details Report – January 2006.
Operating Systems: Deadlock 1 Deadlock Examples: Traffic Jam : Dining Philosophers Device allocation –process 1 requests tape drive 1 & gets it –process.
Chapter 8: Deadlocks Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection Recovery from Deadlock.
CS6502 Operating Systems - Dr. J. Garrido Deadlock – Part 2 (Lecture 7a) CS5002 Operating Systems Dr. Jose M. Garrido.
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.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 3 CPUs.
Mi-Jung Choi Dept. of Computer and Science Silberschatz, Galvin and Gagne ©2006 Operating System Principles Chapter 7: Deadlocks.
by D. Fisher (2 + 1) + 4 = 2 + (1 + 4) Associative Property of Addition 1.
RXQ Customer Enrollment Using a Registration Agent (RA) Process Flow Diagram (Move-In) Customer Supplier Customer authorizes Enrollment ( )
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
Threads, SMP, and Microkernels Chapter 4 1. Process Resource ownership - process includes a virtual address space to hold the process image Scheduling/execution-
1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 7: Deadlocks.
BMU – KI III 1 Development of renewable energy sources in Germany in
Chapter 7. Deadlocks. Outline Deadlock Problem: Definition Methods for Handling Deadlocks –Deadlock Prevention – Deadlock Avoidance – Deadlock Detection.
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
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.
© 2017 SlidePlayer.com Inc. All rights reserved.