Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 7: Deadlocks.

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Chapter 7: Deadlocks Adapted by Donghui Zhang from the original version by Silberschatz et al.
Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition 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 ©2009 Operating System Concepts – 8 th Edition, Lecture 12: Deadlocks (Chapter 7)
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 Deadlocks  (How to Detect Them and Avoid Them) A:
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.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Lecture 7: Deadlocks, Deadlock Risk Management. Lecture 7 / Page 2AE4B33OSS Silberschatz, Galvin and Gagne ©2005 Contents The Concept of Deadlock Resource-Allocation.
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.
Chapter 7: Deadlocks. 7.2 Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks.
1 Chapter 7: Deadlock. 2 The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Chapter 8: Deadlocks System Model Deadlock Characterization
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Bridge Crossing Example Traffic only in one direction. Each section.
Deadlocks Gordon College Stephen Brinton. Deadlock Overview The Deadlock Problem System Model Deadlock Characterization Methods for Handling 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.
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  Operating System Concepts Chapter 8: Deadlocks System Model Deadlock Characterization Methods for Handling 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.
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
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 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.
 The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock Avoidance  Deadlock.
Dr. Kalpakis CMSC 421, Operating Systems Deadlocks.
Operating System Concepts 7th Edition Abraham SilBerschatz Peter Baer Galvin Greg Gagne Prerequisite: CSE212.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
Deadlocks System Model RAG Deadlock Characterization
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.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks System Model Deadlock Characterization Methods.
Mi-Jung Choi Dept. of Computer and Science Silberschatz, Galvin and Gagne ©2006 Operating System Principles Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition, Chapter 7: Deadlocks.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 7 Operating Systems.
Operating Systems Unit VI Deadlocks and Protection Department of Computer Science Engineering and Information Technology.
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.
國立台灣大學 資訊工程學系 Chapter 7: Deadlocks. 資工系網媒所 NEWS 實驗室 Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes.
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.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
Deadlock. Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 8: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition 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 Objectives To develop a description of deadlocks, which.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
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.
L ECTURE 7: D EADLOCKS Dr. nermin Hamza 1. T HE D EADLOCK P ROBLEM A set of blocked processes each holding a resource and waiting to acquire a resource.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
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);
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.
Presentation transcript:

Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 7: Deadlocks

7.2 Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection Recovery from Deadlock

7.3 Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks To present a number of different methods for preventing or avoiding deadlocks in a computer system

7.4 The Deadlock Problem A set of blocked processes each holding a resource and waiting to acquire another resource held by another process in the set Example System has 2 disk drives P 1 and P 2 each hold one disk drive and each needs another one Example semaphores A and B, initialized to 1 P 0 P 1 wait (A);wait(B) wait (B);wait(A)

7.5 System Model Resource types R 1, R 2,..., R m CPU cycles, memory space, I/O devices Each resource type R i has W i instances Assumed to be identical and interchangeable Each process utilizes a resource in three steps: Request  System call like “request()”, “open()”, “allocate()” Use  Whatever the process needs the resource for Release  System call like “release()”, “close()”, “free()”

7.6 Deadlock Characterization Deadlock can arise if four conditions hold simultaneously Mutual exclusion: only one process at a time can use a resource Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task Circular wait: there exists a set {P 0, P 1, …, P n } of waiting processes such that P 0 is waiting for a resource that is held by P 1, P 1 is waiting for a resource that is held by P 2, …, P n–1 is waiting for a resource that is held by P n, and P n is waiting for a resource that is held by P 0

7.7 Resource-Allocation Graph A directed graph that represents the system’s resource allocation among processes Vertices include the set of all processes P (circles) and of all resources R (squares) including all instances of that resource Edge direction represents a process requesting a resource (request edge P i  R j ) or an instance of a resource being allocated to a process (assignment edge R j  P i ) PiPi PiPi RjRj RjRj PiPi RjRj

7.8 Resource-Allocation Graph

7.9 Resource-Allocation Graph

7.10 Resource-Allocation Graph

7.11 If graph contains no cycles  there is no deadlock If graph contains a cycle  there might be a deadlock Resource-Allocation Graph

7.12 Handling Deadlocks Three ways to deal with deadlocks Ensure that the system will never enter a deadlock state  Deadlock prevention & deadlock avoidance Allow the system to enter a deadlock state, detect it, and then recover  Deadlock detection & deadlock recovery Ignore the problem and pretend that deadlocks never occur in the system  User programs have to realize by themselves that they are in deadlock, and programmer has to include code to handle it  Otherwise, program is “not responding” and user terminates it  Used by most operating systems, including UNIX and Windows

7.13 Deadlock Prevention Deadlock can arise if four conditions hold simultaneously Mutual exclusion, hold and wait, no preemption, circular wait We can prevent deadlocks by preventing any one of them Mutual Exclusion Cannot be avoided, as some resources are intrinsically non- sharable Critical-section data, for example Hold and Wait Must guarantee that whenever a process requests a resource, it does not hold any other resources  Process requests all resources it needs at once at creation time  Process requests one resource at a time, and only gets another when it’s done  Low resource utilization, limits concurrency, possible starvation

7.14 Deadlock Prevention No Preemption If a process holds some resources and requests another resource that cannot be immediately allocated to it, then all its resources are released If a process requests a resource that is being held by a waiting process, waiting process forced to release it In both cases, process will be restarted only when it can regain its old resources, as well as the new ones that it is requesting Circular Wait Impose an order on all resource types {R 1, R 2,..., R m } A process can request any number of an instance of a resource, but must get all in one request Processes can only requests resources in increasing order  After holding R i process can only get R j if R i < R j Processes can only requests resources in decreasing order  When requesting R i process must have released all resources R j such as R i ≤ R j Can be accomplished by lock-order-verifier programs, like Witness on FreeBSD

7.15 Deadlock Avoidance Requires that the system has some additional information about which resources each process will need Simplest and most useful model requires that each process declare the maximum number of resources of each type that it may need A deadlock-avoidance algorithm can then 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

7.16 Deadlock Avoidance System is in safe state if there exists a sequence of all the processes in the systems such that for each P j, the resources that P j can still request can be satisfied by currently available resources + resources held by all P i, with P i < P j If no such order exists, the system is in an unsafe state An unsafe state may be a deadlock state

7.17 Deadlock Avoidance System with 12 tape drives Max requestedCurrently allocated P P 1 42 P 2 92 Sequence is ok; System is in a safe state System can go into an unsafe state if P 2 requests 2 or 3 more tape drives Will become deadlocked if P 2 requests > 3 drives Our mistake was granting P 2 ’s request out of order, and going into an unsafe state Deadlock-avoidance algorithm has to prevent that

7.18 If we do not actively prevent deadlocks, then deadlocks may occur To correct the situation, we need Deadlock detection algorithm Deadlock recovery scheme Deadlock Detection

7.19 Deadlock Detection If there is a single instance of each resource Wait-For Graph: Variant of the resource-allocation graph, without resources Nodes are processes P i  P j if P i is waiting for P j Periodically invoke an algorithm that searches for a cycle in the graph. If there is a cycle, there exists a deadlock

7.20 When, and how often, to invoke detection algorithm depends on: How often a deadlock is likely to occur? How many processes will be involved? If deadlocks are a frequent problem, the detection algorithm should be invoked often If we invoke it at the beginning of a deadlock, we can not only detect it early but know exactly which processes are responsible If we wait too long, more processes will have become involved, more cycles will have formed, and we won’t know for sure what’s the core problem But if invoked too often, it becomes an expensive overhead Deadlock Detection

7.21 Deadlock Recovery Notify the user and let him manually resolve it Abort some of the processes Preempt some locked resources from the deadlocked processes

7.22 Which processes to abort? Abort all deadlocked processes Abort one process at a time until the deadlock cycle is eliminated  In which order should we choose to abort? – Priority of the process – How long process has computed, and how much longer to completion – Resources the process has used – Resources process needs to complete – How many processes will need to be terminated – Is process interactive or batch Which process to preempt? Minimize “cost”, i.e. number of resources held, process execution time Can the process be rolled back to a safe state? How to avoid starvation? Deadlock Recovery

7.23 Review Consider the Dining Philosopher problem. Show how the four necessary conditions for deadlocks exist in that situation.

7.24 Exercises Read the entire chapter, but skip the parts about the Banker’s Algorithm in various sections If you have the “with Java” textbook, skip the Java sections and subtract 1 to the following section numbers

Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, End of Chapter 7