Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Deadlock.

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.
1 Deadlock Solutions: Avoidance, Detection, and Recovery CS 241 March 30, 2012 University of Illinois.
Ceng Operating Systems Chapter 2.4 : Deadlocks Process concept  Process scheduling  Interprocess communication  Deadlocks Threads.
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 7 – Deadlock and Indefinite Postponement Outline 7.1 Introduction 7.2Examples of Deadlock.
7.4 Resource Concepts Preemptible resources (e.g. processors and main memory) –Can be removed from a process without loss of work Nonpreemptible resources.
Chapter 3 Deadlocks TOPICS Resource Deadlocks The ostrich algorithm
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
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.
Avishai Wool lecture Introduction to Systems Programming Lecture 5 Deadlocks.
Deadlock Chapter 3 R1 R2 P2P1 Allocated Requested.
Deadlock CSCI 444/544 Operating Systems Fall 2008.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Deadlocks Gordon College Stephen Brinton. Deadlock Overview The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks.
Deadlock Chapter 3 Thursday, February 22, Today’s Schedule Assignment #4 from Chapter 3 posted Deadlock - Chapter 3  Skip multiple resources (3.4.2.
Deadlock Questions answered in this lecture: What are the four necessary conditions for deadlock? How can deadlock be prevented? How can deadlock be avoided?
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 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** 
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.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All.
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 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 7 Operating Systems.
Deadlocks Copyright ©: University of Illinois CS 241 Staff1.
Informationsteknologi Monday, October 1, 2007Computer Systems/Operating Systems - Class 111 Today’s class Deadlock.
Deadlocks References –text: Tanenbaum ch.3. Deadly Embrace Deadlock definition –A set of process is dead locked if each process in the set is waiting.
Deadlocks CPE Operating Systems
ICS Deadlocks 6.1 Deadlocks with Reusable and Consumable Resources 6.2 Approaches to the Deadlock Problem 6.3 A System Model –Resource Graphs –State.
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);
Deadlock Operating Systems (CC2011NI) -Mr. Pranoy Man Pradhan.
Deadlock. Examples You can't get a job without experience; you can't get experience without a job. A set of blocked processes each holding a resource.
Chapter 7: Deadlocks. The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Sistem Operasi IKH311 Deadlock. 2 Resources Examples of computer resources printers tape drives tables Processes need access to resources in reasonable.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
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.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
Process Management Deadlocks.
Chapter 7: Deadlocks.
CSE 120 Principles of Operating
ICS Principles of Operating Systems
Deadlock Management.
Chapter 7 – Deadlock and Indefinite Postponement
Chapter 6 : Deadlocks What is a Deadlock?
Deadlocks References text: Tanenbaum ch.3.
Introduction to Operating Systems
ICS 143 Principles of Operating Systems
Lecture 19: Deadlock: Conditions, Detection and Avoidance
Chapter 7 Deadlocks.
Process Deadlocks.
Deadlocks References text: Tanenbaum ch.3.
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
DPNM Lab. Dept. of CSE, POSTECH
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
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
Deadlocks References text: Tanenbaum ch.3.
Chapter 7: Deadlocks.
Deadlock CSE 2431: Introduction to Operating Systems
Presentation transcript:

Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Deadlock

Copyright ©: Nahrstedt, Angrave, Abdelzaher 2 Deadlock

Copyright ©: Nahrstedt, Angrave, Abdelzaher 3 Deadlock Definition What is Deadlock? Two or more processes are deadlocked if each process is waiting on one of the others to proceed Typically, each process holds one resource and is waiting on a resource some other deadlocked process holds What is starvation? A process is starved if it may logically proceed but is overlooked (not given resources) indefinitely by a scheduling or allocation policy Usually, other processes are able to proceed

Copyright ©: Nahrstedt, Angrave, Abdelzaher 4 Requirements for Deadlock What are they?

Copyright ©: Nahrstedt, Angrave, Abdelzaher 5 Requirements for Deadlock Necessary (not sufficient) conditions Mutual exclusion Processes claim exclusive control of the resources they require Hold-and-wait (a.k.a. wait-for) condition Processes hold resources already allocated to them while waiting for additional resources No preemption condition Resources cannot be removed from the processes holding them until used to completion These may lead to deadlock.

Copyright ©: Nahrstedt, Angrave, Abdelzaher 6 Requirements for Deadlock Necessary and sufficient conditions … Mutual exclusion Processes claim exclusive control of the resources they require Hold-and-wait (a.k.a. wait-for) condition Processes hold resources already allocated to them while waiting for additional resources No preemption condition Resources cannot be removed from the processes holding them until used to completion Circular wait condition: deadlock has occurred A circular chain of processes exists in which each process holds one or more resources that are requested by the next process in the chain

Copyright ©: Nahrstedt, Angrave, Abdelzaher 7 Requirements for Deadlock (Dining Philosophers Example) Mutual exclusion Exclusive use of chopsticks Hold and wait condition Hold 1 chopstick, wait for next No preemption condition Cannot force another to drop a chopstick Circular wait condition Each waits for next neighbor to release chopstick

Copyright ©: Nahrstedt, Angrave, Abdelzaher 8 Mutual Exclusion Processes claim exclusive control of the resources they require How to break it?

Copyright ©: Nahrstedt, Angrave, Abdelzaher 9 Wait-for Condition Processes hold resources already allocated to them while waiting for additional resources How to break it?

Copyright ©: Nahrstedt, Angrave, Abdelzaher 10 No Preemption Condition Resources cannot be removed from the processes holding them until used to completion How to break it?

Copyright ©: Nahrstedt, Angrave, Abdelzaher 11 Circular Wait Condition A circular chain of processes exists in which each process holds one or more resources that are requested by the next process in the chain How to break it?

Copyright ©: Nahrstedt, Angrave, Abdelzaher 12 Resource Allocation Graph Nodes Processes Resources Arcs From resource to process = resource assigned to process From process to resource = process requests resource

Copyright ©: Nahrstedt, Angrave, Abdelzaher 13 resource R assigned to process A process B requests, then waits for resource S process C, D are deadlocked for resources T, U assign request Resource Allocation Graph

Copyright ©: Nahrstedt, Angrave, Abdelzaher 14 Strategies Strategies for dealing with Deadlocks detection and recovery dynamic avoidance (at run-time) prevention (by off-line design) negating one of the four necessary conditions

Copyright ©: Nahrstedt, Angrave, Abdelzaher 15 Deadlock Issues Prevention design a system in such a way that deadlocks cannot occur, at least with respect to serially reusable resources. Avoidance impose less stringent conditions than for prevention, allowing the possibility of deadlock, but sidestepping it as it approaches. Detection and Recovery in a system that allows the possibility of deadlock, determine if deadlock has occurred, and which processes and resources are involved. after a deadlock has been detected, clear the problem, allowing the deadlocked processes to complete and the resources to be reused. Usually involves destroying the affected processes and starting them over.

Copyright ©: Nahrstedt, Angrave, Abdelzaher 16 The Default Solution Don’t do anything normally (“ostrich” approach!) detect cheaply: progress timer recover “simply”: restart the system Rationale: make the common path faster and more reliable deadlock prevention, avoidance or detection/recovery algorithms are expensive if deadlock occurs only rarely, it is not worth the overhead to implement any of these algorithms.

Copyright ©: Nahrstedt, Angrave, Abdelzaher 17 Deadlock Prevention Break one of the deadlock conditions. Mutual exclusion Solution: Usually none except to eliminate concurrency (e.g., spooling) Hold-and-Wait condition Solution: Force each process to request all required resources at once. It cannot proceed until all resources have been acquired. Two-phase locking No preemption condition Solution: Allow a process to be aborted by another when competing over a resource Circular wait condition Solution: All resource types are numbered. Processes must request resources in numerical order

Copyright ©: Nahrstedt, Angrave, Abdelzaher 18 Deadlock Avoidance Avoidance: impose less stringent conditions than for prevention, allowing the possibility of deadlock but sidestepping it as it approaches Banker algorithm Each process specifies the maximum number of resources it needs of each type For each request, the system checks if granting this request may lead to a deadlock in the worse case If yes, do not grant the request If no, grant the request

Copyright ©: Nahrstedt, Angrave, Abdelzaher 19 Deadlock Avoidance Banker Algorithm (Dijkstra, 1965) Each customer tells banker the maximum number of resources it needs Customer borrows resources from banker Customer returns resources to banker Customer eventually pays back loan Banker only lends resources if the system will be in a safe state after the loan Safe state - there is a lending sequence such that all customers can take out a loan Unsafe state - there is a possibility of deadlock

Copyright ©: Nahrstedt, Angrave, Abdelzaher 20 Safe State and Unsafe State Safe State there is some scheduling order in which every process can run to completion even if all of them request their maximum number of resources immediately From safe state, the system can guarantee that all processes will finish Unsafe state: no such guarantee Not deadlocked state Some process may be able to complete

Copyright ©: Nahrstedt, Angrave, Abdelzaher 21 Is Allocation (1 0 2) to P1 Safe? If P1 requests max resources, can complete

Copyright ©: Nahrstedt, Angrave, Abdelzaher 22 Run Safety Test If P1 requests max resources, can complete

Copyright ©: Nahrstedt, Angrave, Abdelzaher 23 Allocate to P1, Then

Copyright ©: Nahrstedt, Angrave, Abdelzaher 24 Release - P1 Finishes Now P3 can acquire max resources and release

Copyright ©: Nahrstedt, Angrave, Abdelzaher 25 Release - P3 Finishes Now P4 can acquire max resources and release

Copyright ©: Nahrstedt, Angrave, Abdelzaher 26 Release - P4 Finishes Now P2 can acquire max resources and release

Copyright ©: Nahrstedt, Angrave, Abdelzaher 27 Release - P2 Finishes Now P0 can acquire max resources and release

Copyright ©: Nahrstedt, Angrave, Abdelzaher 28 So P1 Allocation (1 0 2) Is Safe

Copyright ©: Nahrstedt, Angrave, Abdelzaher 29 Is allocation (0 2 0) to P0 Safe? Try to Allocate 2 B to P0

Copyright ©: Nahrstedt, Angrave, Abdelzaher 30 Run Safety Test No Processes may get max resources and release

Copyright ©: Nahrstedt, Angrave, Abdelzaher 31 So Unsafe State- Do Not Enter Return to Safe State and do not allocate resource

Copyright ©: Nahrstedt, Angrave, Abdelzaher 32 P0 Suspended Pending Request When enough resources become available, P0 can awake

Copyright ©: Nahrstedt, Angrave, Abdelzaher 33 Deadlock Detection Check to see if a deadlock has occurred! Single resource per type Can use wait-for graph Check for cycles How?

Copyright ©: Nahrstedt, Angrave, Abdelzaher 34 Wait for Graphs Resource Allocation GraphCorresponding Wait For Graph

Copyright ©: Nahrstedt, Angrave, Abdelzaher 35 Recovery From Deadlock OPTIONS: Kill deadlocked processes, release resources Kill one deadlocked process at a time and release its resources Rollback all or one of the processes to a checkpoint that occurred before they requested any resources Note: with rollback, difficult to prevent indefinite postponement

Copyright ©: Nahrstedt, Angrave, Abdelzaher 36 Notes In general, deadlock detection or avoidance is expensive Must evaluate cost of deadlock against detection or avoidance costs Deadlock avoidance and recovery may cause indefinite postponement Unix and Windows use the Ostrich Algorithm (do nothing)