7/2/2015cse410-25-deadlock © 2006-07 Perkins, DW Johnson and University of Washington1 Deadlock CSE 410, Spring 2008 Computer Systems

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Chapter 7: Deadlocks Adapted by Donghui Zhang from the original version by Silberschatz et al.
Operating Systems Lecture Notes Deadlocks Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
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.
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.
DPNM Lab. Dept. of CSE, POSTECH
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.
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.
1 Chapter 7: Deadlock. 2 The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Modified from Silberschatz, Galvin and Gagne Lecture 13 Chapter 7: Deadlocks.
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.
Chapter 7.1: Deadlocks.
Chapter 8: Deadlocks System Model Deadlock Characterization
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Deadlock and Starvation Deadlock – two or more processes are waiting indefinitely for.
What we will cover…  The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock.
Lecture Topics: 11/13 Semaphores Deadlock Scheduling.
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.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Chapter 7 – Deadlock (Pgs 283 – 306). Overview  When a set of processes is prevented from completing because each is preventing the other from accessing.
Operating Systems Part III: Process Management (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.
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.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
CS333 Intro to Operating Systems Jonathan Walpole.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks System Model Deadlock Characterization Methods.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 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.
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.
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.
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 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.
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 - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
7: Deadlocks1 OPERATING SYSTEMS DEADLOCKS. 7: Deadlocks2 What Is In This Chapter? What is a deadlock? Staying Safe: Preventing and Avoiding Deadlocks.
CSE Operating System Principles Deadlocks. CSE – Operating System Principles2 Overview System Model Deadlock Characterization Methods for.
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);
G.Anuradha Ref:- Galvin
Operating System: DEADLOCKS
Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
G.Anuradha Ref:- Galvin
Deadlocks Session - 13.
Chapter 7: Deadlocks.
CSS430 Deadlocks Textbook Ch8
Presentation transcript:

7/2/2015cse deadlock © Perkins, DW Johnson and University of Washington1 Deadlock CSE 410, Spring 2008 Computer Systems

7/2/2015cse deadlock © Perkins, DW Johnson and University of Washington2 Readings and References Reading »Chapter 8, Operating System Concepts, Silberschatz, Galvin, and Gagne Other References

7/2/2015cse deadlock © Perkins, DW Johnson and University of Washington3 Deadlock Example “When two trains approach each other at a crossing, both shall come to a full stop and neither shall start up again until the other has gone.” »A Treasury of Railroad Folklore, B.A. Botkin & A.F. Harlow, p. 381

7/2/2015cse deadlock © Perkins, DW Johnson and University of Washington4 Simple Traffic Gridlock Example

7/2/2015cse deadlock © Perkins, DW Johnson and University of Washington5 Deadlock Circular waiting for resources »Task A wants what task B has »Task B wants what task A has No progress possible! »Neither can make progress without the other’s resource »Neither will relinquish its own resource... lockOne->Acquire();... lockTwo->Acquire();... lockTwo->Acquire(); lockOne->Acquire(); DEADLOCK!

7/2/2015cse deadlock © Perkins, DW Johnson and University of Washington6 System Model There are tasks and resources »Resources can be logical or physical A task follows these steps to utilize a resource »Acquire the resource If the resource is unavailable, block »Use the resource »Release the resource

C AB D Necessary Conditions for Deadlock Mutual Exclusion »The resource can’t be shared Hold and Wait »Task holds one resource while waiting for another No Preemption »If a task has a resource, it cannot be forced to give it up Circular Wait »A waits for B, B for C, C for D, D for A

7/2/2015cse deadlock © Perkins, DW Johnson and University of Washington8 Is Gridlock an Example of Deadlock? Mutual Exclusion »space-time can only hold one car at a time Hold and wait »I’m here, and I want to turn left, so watch out No preemption »cannons are not allowed in cars at this time Circular wait »blue is waiting for red’s space and vice versa

7/2/2015cse deadlock © Perkins, DW Johnson and University of Washington9 Dealing with Deadlock Deadlock Prevention »Ensure statically that deadlock is impossible Deadlock Avoidance »Ensure dynamically that deadlock is impossible Deadlock Detection and Recovery »Allow deadlock to occur, but notice when it does and try to recover Ignore the Problem »Let the operator untangle it, that's what they're paid for

7/2/2015cse deadlock © Perkins, DW Johnson and University of Washington10 Deadlock Prevention There are four necessary conditions for deadlock Take any one of them away and deadlock is impossible Let’s attack deadlock by »examining each of the conditions »considering what would happen if we threw it out

7/2/2015cse deadlock © Perkins, DW Johnson and University of Washington11 Condition: Mutual Exclusion Usually can't eliminate this condition »some resources are intrinsically non-sharable Examples include printer, write access to a file or record, entry into a section of code However, you can often mitigate this by adding a layer of abstraction »For example, write to a queue of jobs for a shared resource instead of locking the resource to write

7/2/2015cse deadlock © Perkins, DW Johnson and University of Washington12 Condition: Hold and Wait Eliminate partial acquisition of resources Task must acquire all the resources it needs before it does anything »if it can’t get them all, then it gets none Issue: Resource utilization may be low »If you need P for a long time and Q only at the end, you still have to hold Q’s lock the whole time Issue: Starvation prone »May have to wait indefinitely before popular resources are all available at the same time

7/2/2015cse deadlock © Perkins, DW Johnson and University of Washington13 Condition: No Preemption Allow preemption »If a process asks for a resource not currently available, block it and take away all of its other resources »Add the preempted resources to the list of resources the process is waiting for This strategy works for some resources: »CPU state (contents of registers can be spilled to memory) »memory (can be spilled to disk) But not for others: »printer - rip off the existing printout and tape it on later?

7/2/2015cse deadlock © Perkins, DW Johnson and University of Washington14 Condition: Circular Wait To attack the circular wait condition: »Assign each resource a priority »Make processes acquire resources in priority order Two processes need the printer and the scanner, both must acquire the printer (higher priority) before the scanner This is a common form of deadlock prevention The only problem: sometimes forced to relinquish a resource that you thought you had locked up

7/2/2015cse deadlock © Perkins, DW Johnson and University of Washington15 Deadlock Avoidance Deadlock prevention is often too strict »low device utilization »reduced system throughput If the OS had more information, it could do more sophisticated things to avoid deadlock and keep the system in a safe state »“If” is a little word, but it packs a big punch »predicting all needed resources a priori is hard

7/2/2015cse deadlock © Perkins, DW Johnson and University of Washington16 The Banker’s Algorithm Idea: know what each process might ask for Only make allocations that leave the system in a safe state Inefficient safe unsafe deadlock Resource allocation state space

7/2/2015cse deadlock © Perkins, DW Johnson and University of Washington17 Deadlock Detection Build a wait-for graph and periodically look for cycles, to find the circular wait condition The wait-for graph contains: »nodes, corresponding to tasks »directed edges, corresponding to a resource held by one task and desired by the other »O(n^2) »Single instance resources only E C AB D A waits for B B waits for D D waits for A deadlock!

7/2/2015cse deadlock © Perkins, DW Johnson and University of Washington18 Deadlock Recovery Once you’ve discovered deadlock, what next? Terminate one of the tasks to stop circular wait? »Task will likely have to start over from scratch »Which task should you choose? Take a resource away from a task? »Again, which task should you choose? »How can you roll back the task to the state before it had the coveted resource? »Make sure you don’t keep on preempting from the same task: avoid starvation

7/2/2015cse deadlock © Perkins, DW Johnson and University of Washington19 Ignoring Deadlock Not a bad policy for operating systems The mechanisms outlined previously for handling deadlock may be expensive »if the alternative is to have a forced reboot once a year, that might be acceptable However, for thread deadlocks, your users may not be quite so tolerant »“the program only locks up once in a while”

Edsger Djikstra Shortest Path Algorithm »A specific case of A* Banker’s Algorithm research Contributed to threading safety, routing, etc. 7/2/2015cse deadlock © Perkins, DW Johnson and University of Washington20