U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Deadlock Emery Berger and Mark Corner University of Massachusetts.

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

ICS Principles of Operating Systems Lectures 8 and 9 - Deadlocks Prof. Dmitri V. Kalashnikov dvk ics.uci.edu Slides © Prof. Nalini Venkatasubramanian.
Deadlock and Starvation
Operating Systems Lecture Notes Deadlocks Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
1 Deadlock Solutions: Avoidance, Detection, and Recovery CS 241 March 30, 2012 University of Illinois.
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.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
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.
02/18/2008CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
The ‘deadlock’ conditions Reviewing some key points concerning the potential for ‘deadlock’ in an operating system.
Deadlock Prevention CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Bridge Crossing Example Traffic only in one direction. Each section.
Silberschatz, Galvin and Gagne  Operating System Concepts Deadlock and Starvation Deadlock – two or more processes are waiting indefinitely for.
Deadlock Characterization
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
Deadlock Questions answered in this lecture: What are the four necessary conditions for deadlock? How can deadlock be prevented? How can deadlock be avoided?
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Operating Systems Part III: Process Management (Deadlocks)
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-6 Deadlocks Department of Computer Science and Software Engineering.
Operating Systems (OS)
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
This Time - Deadlock Definition Conditions for deadlocks
CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
Deadlock cs550 Operating Systems David Monismith.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Synchronization Emery Berger and Mark Corner University.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
Styresystemer og Multiprogrammering Block 3, 2005 Deadlocks Robert Glück.
CS307 Operating Systems Deadlocks Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2012.
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 12/02/2015. What is a deadlock ? System has a finite set of resources. Resource can have one or more instances. Processes compete for resources.
Deadlocks Copyright ©: University of Illinois CS 241 Staff1.
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 7: Deadlocks.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Deadlock.
Chapter 7: Deadlocks.
OPERATING SYSTEM CONCEPTS AND PRACTISE
Process Management Deadlocks.
Synchronization Deadlocks and prevention
Chapter 7: Deadlocks.
Synchronization Deadlocks and prevention
CSE 120 Principles of Operating
Deadlock Management.
ITEC 202 Operating Systems
Chapter 7: Deadlocks Source & Copyright: Operating System Concepts, Silberschatz, Galvin and Gagne.
Chapter 7: Deadlocks.
Operating System: DEADLOCKS
Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
CSCI 511 Operating Systems Chapter 7 Deadlock
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.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Deadlock B.Ramamurthy CSE421 1/11/2019 B.Ramamurthy.
Chapter 7: Deadlocks.
Outline Deadlocks, dead lock prevention, avoidance.
DPNM Lab. Dept. of CSE, POSTECH
Deadlock B.Ramamurthy CSE421 2/23/2019 B.Ramamurthy.
Deadlocks Session - 13.
DEADLOCK.
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 4/23/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 5/1/2019 B.Ramamurthy.
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:

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Deadlock Emery Berger and Mark Corner University of Massachusetts Amherst

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 2 thread A printer->wait(); disk->wait(); thread B disk->wait(); printer->wait(); Deadlocks  Deadlock = condition where two threads/processes wait on each other

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Example: Dining Philosophers  Another gift from Dijkstra

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 4 Deadlocks - Terminology  Deadlock  Deadlock prevention algorithms –Check resource requests & availability  Deadlock detection –Finds instances of deadlock when threads stop making progress –Tries to recover

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 5 Rules for Deadlock  All necessary and none sufficient

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 6 Rules for Deadlock  All necessary and none sufficient  Finite resource –Resource can be exhausted causing waiting

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 7 Rules for Deadlock  All necessary and none sufficient  Finite resource –Resource can be exhausted causing waiting  Hold and wait –Hold resource while waiting for another

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 8 Rules for Deadlock  All necessary and none sufficient  Finite resource –Resource can be exhausted causing waiting  Hold and wait –Hold resource while waiting for another  No preemption –Thread can only release resource voluntarily –No other thread or OS can force thread to release

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 9 Rules for Deadlock  All necessary and none sufficient  Finite resource –Resource can be exhausted causing waiting  Hold and wait –Hold resource while waiting for another  No preemption –Thread can only release resource voluntarily –No other thread or OS can force thread to release  Circular wait –Circular chain of waiting threads

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 10 Circular Waiting  If no way to free resources (preemption)

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 11 Deadlock Detection  Define graph with vertices: –Resources = {r1, …, rm} –Threads = {t1, …, tn}  Request edge from thread to resource –(ti → rj)  Assignment edge from resource to thread –(rj → ti) –OS has allocated resource to thread  Result: –No cycles  no deadlock –Cycle  may deadlock

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 12 Example  Deadlock or not?  Request edge from thread to resource ti -> rj –Thread: requested resource but not acquired it (waiting)  Assignment edge from resource to thread rj -> ti –OS has allocated resource to thread

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 13 Quick Exercise  Draw a graph for the following event:  Request edge from thread to resource –ti -> rj  Assignment edge from resource to thread –rj -> ti

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 14 Resource Allocation Graph  Draw a graph for the following event:

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 15 Detecting Deadlock  Scan resource allocation graph for cycles –Then break them!  Different ways to break cycles: –Kill all threads in cycle –Kill threads one at a time Force to give up resources –Preempt resources one at a time Roll back thread state to before acquiring resource Common in database transactions

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 16 Deadlock Prevention  Instead of detection, ensure at least one of necessary conditions doesn’t hold –Mutual exclusion –Hold and wait –No preemption –Circular wait

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 17 Deadlock Prevention  Mutual exclusion –Make resources shareable (but not all resources can be shared)  Hold and wait –Guarantee that thread cannot hold one resource when it requests another –Make threads request all resources they need first and release all before requesting more

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 18 Deadlock Prevention, continued  No preemption –If thread requests resource that cannot be immediately allocated to it OS preempts (releases) all resources thread currently holds –When all resources available: OS restarts thread  Not all resources can be preempted!

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 19 Deadlock Prevention, continued  Circular wait –Impose ordering (numbering) on resources and request them in order –Most important trick to correct programming with locks!

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 20 Avoiding Deadlock  Cycle in locking graph = deadlock  Typical solution: canonical order for locks –Acquire in increasing order E.g., lock_1, lock_2, lock_3 –Release in decreasing order  Ensures deadlock-freedom –but not always easy to do

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 21 lock (a); lock (b); unlock (b); unlock (a); lock (b); lock (a); unlock (a); unlock (b); Avoiding Deadlock  Avoiding deadlock: is this ok?

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 22 lock (a); lock (b); unlock (b); unlock (a); lock (b); lock (a); unlock (a); unlock (b); lock (a); lock (b); unlock (b); unlock (a); lock (a); lock (b); unlock (b); unlock (a); Avoiding Deadlock  Not ok – may deadlock.  Solution: impose canonical order (acyclic)

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science

24 Deadlocks, Example II

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 25 Multiple Resources  What if there are multiple interchangeable instances of a resource? –Cycle  deadlock might exist –If any instance held by thread outside cycle, progress possible when thread releases resource

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 26 Deadlock Detection Deadlock or not?