Chapter 7: Deadlock 11.4.2008. Course Administration n Midterm exam next week in class l Closed book n Final exam time changed to 1.13.2009 during class.

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

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)
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 30 Handling Deadlock.
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.
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
03/07/2007CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
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.
03/03/2004CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Deadlocks Gordon College Stephen Brinton. Deadlock Overview The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks.
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 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.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Objectives Understand the Deadlock.
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
 The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock Avoidance  Deadlock.
Dr. Kalpakis CMSC 421, Operating Systems Deadlocks.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks System Model Deadlock Characterization Methods.
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.
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.
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.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 8: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks.
Deadlocks Introduction to Operating Systems: Module 7.
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.
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 - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
CSE Operating System Principles Deadlocks. CSE – Operating System Principles2 Overview System Model Deadlock Characterization Methods for.
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.
OPERATING SYSTEM CONCEPTS AND PRACTISE
Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
Outline Deadlocks, dead lock prevention, avoidance.
Deadlock Prevention Restrain the ways request can be made.
Deadlocks Session - 14.
Chapter 7: Deadlocks.
Presentation transcript:

Chapter 7: Deadlock

Course Administration n Midterm exam next week in class l Closed book n Final exam time changed to during class time. l Avoid conflict with other courses.

Outline n What is a deadlock? n How to deal with a deadlock? n Deadlock detection n Deadlock prevention n Single-instance: wait-for graph n Multi-instance: banker’s algorithm

4 Deadlocks n X(A) = request exclusive lock A l Wait on mutex semaphore A n T1 and T2 will make no further progress. n When can deadlock occur? n How to handle deadlock? l Prevent deadlocks from occurring. l Detection deadlocks and resolve them. n How to do deadlock prevention and detection? T1T2 X(A) X(B) Request X(B) Blocked! Request X(A) Blocked too!

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

6 Single-instance Deadlock Detection n Resource type: l Single-Instance: mutex l Multi-Instance: CPUs n Create a waits-for graph: l Nodes are processes/transactions l There is an edge from Ti to Tj if Ti is waiting for Tj to release a lock n Periodically check for cycles in the waits-for graph, l cycle = Deadlock l Resolve a deadlock by aborting a process a cycle. T1T2 S(A) R(A)S(B) R(B) X(B): W(B) X(A): W(A)

Single-Instance Wait-For-Graph 7 T1T2 T4T3 T1T2 T4T3 T1T2T3T4 S(A) R(A) X(B) W(B) S(B) S(C) R(C) X(C) X(B) X(A)

8 Single-instance Deadlock Prevention n Make sure that deadlock will not occur. n How to do it? l Assign priorities to transactions based on timestamps when they start up. (lower timestamps = higher priority) l Lower priorities cannot wait for higher-priority transactions.

9 Single-instance Deadlock Prevention n Say Ti wants a lock that Tj holds. What would a deadlock prevention policy do? l Wait-Die: If Ti has higher priority, Ti waits for Tj; otherwise Ti aborts (lower-priority T never waits for higher-priority T) l Wound-wait: If Ti has higher priority, Tj aborts; otherwise Ti waits. (higher-priority T never waits for lower-priority T) n Why these two policies prevent deadlocks? l The oldest transaction (highest priority one) will eventually get all the locks it requires!

10 Wait-Die Policy n Lower-priority process never waits for higher- priority process n If Ti has higher priority, Ti waits for Tj; n Otherwise Ti aborts T1T2T3T4 S(A) R(A) X(B) W(B) S(B) S(C) R(C) X(C) X(B) // abort X(A) // abort

11 Wound-Wait Policy n Higher-priority process never waits for lower-priority T n If Ti has higher priority, Tj aborts; n Otherwise Ti waits. T1T2T3T4 S(A) R(A) X(B) W(B) S(B) // Abort T2Abort

12 Single-instance Deadlock Prevention (2) n If a transaction re-starts, make sure it has its original timestamp. l It will not be forever aborted due to low priority.

Multi-instance Deadlock n Single instance of a resource type. l Detection: Use a wait-for graph n Multiple instances of a resource type – Banker’s algorithm l Deadlock-free or safe state detection : safety algorithm l Deadlock prevention: resource-request algorithm l Deadlock detection: detection algorithm l All three algorithms use similar data structure.

08:35 /4314 Multi-instance example P1P1 P2P2 P3P3 R 2 R 1

Common Data Structure n Let n = number of processes, and m = number of resources types. n Available: Vector of length m. If available [j] = k, there are k instances of resource type R j available. n Max: n x m matrix. If Max [i,j] = k, then process P i may request at most k instances of resource type R j. n Allocation: n x m matrix. If Allocation[i,j] = k then P i is currently allocated k instances of R j. n Need: n x m matrix. If Need[i,j] = k, then P i may need k more instances of R j to complete its task. Need [i,j] = Max[i,j] – Allocation [i,j].

Safety Algorithm n Safety algorithm means … l Is the system (given Available, Need, Allocation matrices) deadlock free? l Does there exist a schedule for all processes to complete their execution without a deadlock? 1. Let Work and Finish be vectors of length m and n, respectively. Initialize: Work = Available Finish [i] = false for i = 0, 1, …, n Find and i such that both: (a) Finish [i] = false (b) Need i  Work If no such i exists, go to step Work = Work + Allocation i Finish[i] = true go to step If Finish [i] == true for all i, then the system is in a safe state.

Example of Safety Algorithm n 5 processes P 0 through P 4 ; n 3 resource types: l A (10 instances), B (5instances), and C (7 instances). n Snapshot at time T 0 : AllocationNeedAvailable A B CA B C A B C P P P P P n A safe sequence

Resource-Request Algorithm for Process P i Can a request be safety granted without causing a deadlock? Request = request vector for process P i. If Request i [j] = k then process P i wants k instances of resource type R j. 1. If Request i  Need i go to step 2. Otherwise, raise error condition, since process has exceeded its maximum claim. 2. If Request i  Available, go to step 3. Otherwise P i must wait, since resources are not available. 3. Pretend to allocate requested resources to P i by modifying the state as follows: Available = Available – Request; Allocation i = Allocation i + Request i ; Need i = Need i – Request i ; l If safe  the resources are allocated to Pi. l If unsafe  Pi must wait, and the old resource-allocation state is restored

Example of Resource-Request Algorithm n 5 processes P 0 through P 4 ; n 3 resource types: A (10 instances), B (5instances), and C (7 instances). n Snapshot at time T 0, say P 1 Request (1,0,2) AllocationNeedAvailable A B CA B C A B C P P P P P n A safe sequence

Detection Algorithm Check if there is a deadlock in the system. 1. Let Work and Finish be vectors of length m and n, respectively Initialize: (a) Work = Available (b) For i = 1,2, …, n, if Allocation i  0, then Finish[i] = false;otherwise, Finish[i] = true. 2. Find an index i such that both: (a) Finish[i] == false (b) Request i  Work If no such i exists, go to step Work = Work + Allocation i Finish[i] = true go to step If Finish[i] == false, for some i, 1  i  n, then the system is in deadlock state. Moreover, if Finish[i] == false, then P i is deadlocked.

Example of Detection Algorithm n Five processes P 0 through P 4 ; three resource types A (7 instances), B (2 instances), and C (6 instances). n Snapshot at time T 0 : AllocationRequestAvailable A B C A B C A B C P P P P P n Sequence will result in Finish[i] = true for all i.

Example (Cont.) n P 2 requests an additional instance of type C. Request A B C P P P P P n State of system? l Can reclaim resources held by process P 0, but insufficient resources to fulfill other processes; requests. l Deadlock exists, consisting of processes P 1, P 2, P 3, and P 4.

Detection-Algorithm Usage n When, and how often, to invoke depends on: l How often a deadlock is likely to occur? l How many processes will need to be rolled back?  one for each disjoint cycle n If detection algorithm is invoked arbitrarily, there may be many cycles in the resource graph and so we would not be able to tell which of the many deadlocked processes “caused” the deadlock.

Recovery from Deadlock: Process Termination n Abort all deadlocked processes. n Abort one process at a time until the deadlock cycle is eliminated. n In which order should we choose to abort? l Priority of the process. l How long process has computed, and how much longer to completion. l Resources the process has used. l Resources process needs to complete. l How many processes will need to be terminated. l Is process interactive or batch?

Summary n What is a deadlock? n How to deal with a deadlock? l Deadlock detection l Deadlock prevention n Single-instance: wait-for graph n Multi-instance: banker’s algorithm l Safety algorithm l Resource-allocation algorithm l Detection algorithm

End of Chapter 7