Deadlocks Vivek Pai / Kai Li Princeton University.

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

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.
Deadlocks Today Resources & deadlocks Dealing with deadlocks Other issues Next Time Memory management.
6. Deadlocks 6.1 Deadlocks with Reusable and Consumable Resources
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Chapter 3 Deadlocks TOPICS Resource Deadlocks The ostrich algorithm
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
Tanenbaum Ch 6 Silberschatz Ch 7
With slides from C. Griwodz, K. Li, A. Tanenbaum and M. van Steen
Avishai Wool lecture Introduction to Systems Programming Lecture 5 Deadlocks.
DPNM Lab. Dept. of CSE, POSTECH
Deadlock Chapter 3 R1 R2 P2P1 Allocated Requested.
Multi-Object Synchronization. Main Points Problems with synchronizing multiple objects Definition of deadlock – Circular waiting for resources Conditions.
Deadlocks Tore Larsen With slides from T. Plagemann, C. Griwodz, K. Li, A. Tanenbaum and M. van Steen.
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.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
Deadlock Chapter 3 Thursday, February 22, Today’s Schedule Assignment #4 from Chapter 3 posted Deadlock - Chapter 3  Skip multiple resources (3.4.2.
CH 3 Deadlock When 2 (or more) processes remain blocked forever!
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks Modified.
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.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance 3.6. Deadlock prevention.
1 Deadlocks 2 Resources Examples of computer resources –printers –tape drives –tables Processes need access to resources in reasonable order Suppose.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
1 Deadlocks Chapter 3. 2 Resources Examples of computer resources –printers –tape drives –tables Processes need access to resources in reasonable order.
Operating Systems 软件学院 高海昌 Operating Systems Gao Haichang, Software School, Xidian University 22 Contents  1. Introduction** 
Operating Systems Part III: Process Management (Deadlocks)
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
1 MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All.
CS6502 Operating Systems - Dr. J. Garrido Deadlock – Part 2 (Lecture 7a) CS5002 Operating Systems Dr. Jose M. Garrido.
This Time - Deadlock Definition Conditions for 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.
CSC 322 Operating Systems Concepts Lecture - 28: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Mi-Jung Choi Dept. of Computer and Science Silberschatz, Galvin and Gagne ©2006 Operating System Principles Chapter 7: Deadlocks.
Operating Systems COMP 4850/CISG 5550 Deadlocks Dr. James Money.
Chapter 8 Deadlocks. Objective System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection.
Chapter 5 Process Management Semester 2. Objectives  What is a deadlock?  Seven cases of deadlocks  Conditions of deadlocks –Mutual exclusion.
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 7: Deadlocks.
CH 3 Deadlock When 2 (or more) processes remain blocked forever!
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);
Sistem Operasi IKH311 Deadlock. 2 Resources Examples of computer resources printers tape drives tables Processes need access to resources in reasonable.
Deadlocks Lots of resources can only be used by one process at a time. Exclusive access is needed. Suppose process A needs R1 + R2 and B needs R1 + R2.
Process Management Deadlocks.
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Deadlock Management.
Chapter 7: Deadlocks Source & Copyright: Operating System Concepts, Silberschatz, Galvin and Gagne.
Introduction to Operating Systems
Lecture 19: Deadlock: Conditions, Detection and Avoidance
Process Deadlocks.
Chapter 7: Deadlocks.
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Deadlocks Session - 13.
Lecture 27 Syed Mansoor Sarwar
Lecture 19: Deadlock: Conditions, Detection and Avoidance
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Introduction to Deadlocks
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Presentation transcript:

Deadlocks Vivek Pai / Kai Li Princeton University

2 Bankgedanken How much money do banks keep? What is a bank run? How do you handle it?

3 Mechanics Dec 10 class canceled Readings – sketchy from here on Next project – VM Wednesday night midterm discussion 8:30pm, room 105 Rough “grades” will be sent out soon

4 Let’s Talk About Deadlocks wish I’d read Chapter 3

5 Definitions Resources Preemptable (can be taken away): CPU Non-preemptable (cannot be taken away): Disk, files, mutex,... Starvation Processes/threads wait indefinitely Typical way to use a resource Request Use Release

6 Resource Allocation Graph Process A is holding resource R Process B requests resource S A cycle in the resource allocation graph means that there is deadlock If A requests for S while holding R, and B requests for R while holding S, then AR BS AS BR

7 An Example A utility program copies a file from a tape to disk prints the file to a printer Resources tape disk printer A deadlock tapediskprinter A B

8 What Causes Deadlocks? Guns don’t cause deadlocks – people do

9 Conditions for Deadlock Mutual exclusion condition Each resource is assigned to exactly one process Hold and Wait Multiple independent requests No preemption Resources cannot be taken away Circular chain of requests Note: eliminating any condition eliminates deadlock

10 Eliminate Competition for Resources? If running A to completion and then running B, there will be no deadlock Generalize this idea for all processes? Is it a good idea to develop a CPU scheduling algorithm that causes no deadlock? AS BR Previous example

11 Strategies Ignore the problem It is user’s fault Detection and recovery Fix the problem afterwards Dynamic avoidance Careful allocation Prevention Negate one of the four conditions

12 Detection and Recovery Detection Scan resource graph Detect cycles Recovery (difficult) Kill process/threads (can you always do this?) Roll back actions of deadlocked threads What about the tape-disk-printer example?

13 Avoidance Banker’s algorithm for a single resource Each process has a credit Total resources may not satisfy all credits Keep track of resources assigned and needed Check on each allocation whether it is safe Safe: there exists a sequence of other states that all processes can terminate correctly Multiple resources Read textbook for details

14 Practical Avoidance Two-phase locking Phase I: Try to lock all resources at the beginning Phase II: If successful, use the resources & release them If not, release all resources and start over What about the tape-disk-printer example?

15 Prevention: Remove Mutual Exclusion Some resources are not sharable Printer, tape, etc Some resources can be made sharable Read-only files, memory, etc Read/write locks Some resources can be made virtual Spooling Does spooling apply to all non-sharable resources? What about the tape-disk-printer example?

16 Prevention: Remove Hold and Wait Method Request for all resources before starting execution If all available, it would run Otherwise, it will wait This is how telephone company prevents deadlocks Problems with this approach? What about the tape-disk-printer example?

17 Prevention: No Preemption Make scheduler aware of resource allocation Method If a request from a process holding resources cannot be satisfied, preempt the process and release all resources Schedule it only if the system satisfies all resources Alternative Preempt the process holding the requested resource Copying Copying to a buffer to release the resource? What about the tape-disk-printer example?

18 Prevention: No Circular Wait Impose an order of requests for all resources Method Assign a unique id to each resource All resource requests must be in an ascending order of the ids Release resources in a descending order Can you prove this method has no circular wait? Does this method work for the tape-disk- printer example?

19 Why Do We Care About This? Two possibilities Bitten all the time by this Strive to never have it Why? Fact of life for some applications Faulty programming in others

20 Parallel Scientific Applications Really expensive machines Overhead counts Parallel programs, shared data Assumption of smart programmers Deadlock detection support is wasted Correct programs don’t use it Incorrect programs don’t survive

21 Data Access in Scientific Apps Lots of small accesses Locks often released quickly Structured data Directed acyclic graphs, trees, etc Predictable patterns of access Result: deadlock avoidance schemes

22 Databases: Insanely Profitable Large amount of shared data Lots of accesses to it Uncoordinated accesses Often no predictability Data-dependent program flow End-users had different concerns Result: good deadlock mechanisms needed

23 Concept of Transactions Simplified description Preserves invariants All-or-nothing behavior Start/end declared No permanent modifications until end Restart capabilities assumed