CompSci 143aSpring, 2013 1 6. Deadlocks 6.1 Deadlocks with Reusable and Consumable Resources 6.2 Approaches to the Deadlock Problem 6.3 A System Model.

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
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
6. Deadlocks 6.1 Deadlocks with Reusable and Consumable Resources
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 Systems Principles Process Management and Coordination Lecture 6: Deadlocks 主講人:虞台文.
Chapter 6 Concurrency: Deadlock and Starvation
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.
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.
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.
Deadlock CSCI 444/544 Operating Systems Fall 2008.
CPSC 4650 Operating Systems Chapter 6 Deadlock and Starvation
1 Concurrency: Deadlock and Starvation Chapter 6.
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.
Deadlocks Gordon College Stephen Brinton. Deadlock Overview The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
Distributed process management: Distributed deadlock
Deadlocks in Distributed Systems Deadlocks in distributed systems are similar to deadlocks in single processor systems, only worse. –They are harder to.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Deadlocks.
System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention, Avoidance, and Detection Recovering from Deadlock Combined Approach.
Operating Systems Part III: Process Management (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.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
 The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock Avoidance  Deadlock.
Dr. Kalpakis CMSC 421, Operating Systems Deadlocks.
CS 346 – Chapter 7 Deadlock –Properties –Analysis: directed graph Handle –Prevent –Avoid Safe states and the Banker’s algorithm –Detect –Recover.
Deadlocks System Model RAG Deadlock Characterization
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
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.
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.
CS307 Operating Systems Deadlocks Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2012.
Deadlock. Stepping on each other’s feet - I Thread T 1 b1:= allocate(); b2:= allocate(); …… release(b1); release(b2); Thread T 2 b1:= allocate(); b2:=
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.
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);
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.
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.
CSE 120 Principles of Operating
Concurrency: Deadlock and Starvation
Deadlock Management.
ITEC 202 Operating Systems
Chapter 7 Deadlock.
Chapter 7 Deadlocks.
Process Deadlocks.
Deadlock B.Ramamurthy CSE421 1/11/2019 B.Ramamurthy.
Lecture 6: Deadlocks, Deadlock Risk Management
Deadlock B.Ramamurthy CSE421 2/23/2019 B.Ramamurthy.
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 4/23/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 5/1/2019 B.Ramamurthy.
Operating Systems Principles Process Management and Coordination Lecture 6: Deadlocks 主講人:虞台文.
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 8/28/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 9/3/2019 B.Ramamurthy.
Presentation transcript:

CompSci 143aSpring, Deadlocks 6.1 Deadlocks with Reusable and Consumable Resources 6.2 Approaches to the Deadlock Problem 6.3 A System Model –Resource Graphs –State Transitions –Deadlock States and Safe States 6.4 Deadlock Detection –Reduction of Resource Graphs –Special Cases of Deadlock Detection –Deadlock Detection in Distributed Systems 6.5 Recovery from Deadlock 6.6 Dynamic Deadlock Avoidance –Claim Graphs –The Banker’s Algorithm 6.7 Deadlock Prevention

CompSci 143aSpring, Deadlocks Informal definition: Process is blocked on resource that will never be released. Deadlocks waste resources Deadlocks are rare: –Many systems ignore them Resolved by explicit user intervention –Critical in many real-time applications May cause damage, endanger life

CompSci 143aSpring, Reusable/Consumable Resources Reusable Resources –Number of units is “constant” –Unit is either free or allocated; no sharing –Process requests, acquires, releases units Examples: memory, devices, files, tables Consumable Resources –Number of units varies at runtime –Process may create new units –Process may consume units Examples: messages, signals

CompSci 143aSpring, Examples of Deadlocks p1:... p2:... open(f1,w); open(f2,w); open(f2,w); open(f1,w); Deadlock when executed concurrently p1: if (C) send(p2,m); p2:... while(1){... while(1){... recv(p2,m); recv(p1,m); send(p2,m); send(p1,m);... }... } Deadlock when C not true

CompSci 143aSpring, Deadlock, Livelock, Starvation Deadlock: Processes are blocked Livelock: Processes run but make no progress Both deadlock and livelock lead to starvation Starvation may have other causes –ML scheduling where one queue is never empty –Memory requests: unbounded stream of 100MB requests may starve a 200MB request

CompSci 143aSpring, Approaches to Deadlock Problem 1.Detection and Recovery –Allow deadlock to happen and eliminate it 2.Avoidance (dynamic) –Runtime checks disallow allocations that might lead to deadlocks 3.Prevention (static) Restrict type of request and acquisition to make deadlock impossible

CompSci 143aSpring, System Model for Deadlock Detection, Avoidance, etc. Assumptions: –When a process requests a resource, either the request is fully granted or the process blocks –No partial allocation –A process can only release resources that it holds Resource graph: –Vertices are processes, resources, resource units –Edges (directed) represent requests and allocations of resources

CompSci 143aSpring, System Model: Resource Graph Resource graph: Process = Circle Resource = Rectangle with small circles for each unit Request = Edge from process to resource class Allocation = Edge from resource unit to process Figure 6-1

CompSci 143aSpring, System Model: State Transitions Request: Create new request edge p i  R j –p i has no outstanding requests –number of edges between p i and R j cannot exceed total units of R j Acquisition: Reverse request edge to p i  R j –All requests of p i are satisfiable –p i has no outstanding requests Release: Remove edge p i  R j Figure 6-2

CompSci 143aSpring, System Model A process is blocked in state S if it cannot request, acquire, or release any resource. A process is deadlocked in state S if it is currently blocked now and remains blocked in all states reachable from state S A state is a deadlock state if it contains a deadlocked process. State S is a safe state if no deadlock state can be reached from S by any sequence of request, acquire, release.

CompSci 143aSpring, Example 2 processes p 1, p 2 ; 2 resources R 1, R 2, p 1 and p 2 both need R 1 and R 2 p 1 requests R 1 before R 2 and releases R 2 before R 1 p 2 requests R 2 before R 1 and releases R 1 before R 2 Figure 6-3: Transitions by p 1 only

CompSci 143aSpring, Example p 1 and p 2 both need R 1 and R 2 p 1 requests R 1 before R 2 and releases R 2 before R 1 p 2 requests R 2 before R 1 and releases R 1 before R 2 Figure 6-4: Transitions by p 1 and p 2

CompSci 143aSpring, Deadlock Detection Graph Reduction: Repeat the following 1.Select unblocked process p 2.Remove p and all request and allocation edges Deadlock  Graph not completely reducible. All reduction sequences lead to the same result. Figure 6-5

CompSci 143aSpring, Special Cases of Detection Testing for whether a specific process p is deadlocked: –Reduce until p is removed or graph irreducible Continuous detection: 1.Current state not deadlocked 2.Next state T deadlocked only if: a. Operation was a request by p and b. p is deadlocked in T 3.Try to reduce T by p

CompSci 143aSpring, Special Cases of Detection Immediate allocations –All satisfiable requests granted immediately –Expedient state: state with no satisfiable request edges –If all requests are granted immediately, all states are expedient. Not expedient (p1->R1)

CompSci 143aSpring, Special Cases of Detection Immediate allocations, continued. –Knot : A set K of nodes such that Every node in K reachable from any other node in K No outgoing edges from any node in K –Knot in expedient state  Deadlock : –Reason: All processes in K must have outstanding requests Expedient state means requests not satisfiable (Remove R2->p1: knot R2,p3,R3,p5) (Reverse edge p1->R1): expedient state

CompSci 143aSpring, Special Cases of Detection For single-unit resources, cycle  deadlock –Every p must have a request edge to R –Every R must have an allocation edge to p –R is not available and thus p is blocked Wait-For Graph (wfg): Show only processes –Replace p 1  R  p 2 by p 1  p 2 : p 1 waits for p 2 Figure 6-6

CompSci 143aSpring, Deadlock detection in Distributed Systems Central Coordinator (CC) –Each machine maintains a local wfg –Changes reported to CC –CC constructs and analyzes global wfg Problems –Coordinator is a performance bottleneck –Communication delays may cause phantom deadlocks Figure 6-7

CompSci 143aSpring, Detection in Distributed Systems Distributed Approach –Detect cycles using probes. –If process p i blocked on p j, it launches probe p i  p j –pj sends probe p i  p j  p k along all request edges, etc. –When probe returns to p i, cycle is detected Figure 6-8

CompSci 143aSpring, Recovery from Deadlock Process termination –Kill all processes involved in deadlock; or –Kill one at a time. In what order? By priority: consistent with scheduling By cost of restart: length of recomputation By impact on other processes: CS, producer/consumer Resource preemption –Direct: Temporarily remove resource (e.g., Memory) –Indirect: Rollback to earlier “checkpoint”

CompSci 143aSpring, Dynamic Deadlock Avoidance Maximum Claim Graph –Process indicates maximum resources needed –Potential request edge p i  R j (dashed) –May turn into real request edge Figure 6-9

CompSci 143aSpring, Dynamic Deadlock Avoidance Theorem: Prevent acquisitions that do not produce a completely reducible graph  All state are safe. Banker’s algorithm (Dijkstra): –Given a satisfiable request, p  R, temporarily grant request, changing p  R to R  p –Try to reduce new claim graph, treating claim edges as actual requests. –If new claim graph is completely reducible proceed. If not, reverse temporary acquisition R  p back to p  R Analogy with banking: resources correspond to currencies, allocations correspond to loans, maximum claims correspond to credit limits

CompSci 143aSpring, Example of banker’s algorithm Claim graph (a). Which requests for R1 can safely be granted? If p1’s request is granted, resulting claim graph (b) is reducible (p1,p3,p2). If p2’s request is granted, resulting claim graph (c) is not reducible. Exercise: what about p3’s request? Figure 6-10

CompSci 143aSpring, Dynamic Deadlock Avoidance Special Case: Single-unit resources –Check for cycles after tentative acquisition Disallow if cycle is found (cf. Fig 6-11(a)) –If claim graph contains no undirected cycles, all states are safe (cf. Fig 6-11(b)) (Because no directed cycle can ever be formed.) Figure 6-11

CompSci 143aSpring, Deadlock Avoidance – Another Approach Restrict waits to avoid “wait for” cycles. Each process has timestamp. Ensure that either –Younger process never waits for older process; or –Older process never waits for younger process When process R requests resource that process H holds (two variants) 1.Wait/die algorithm: (Younger process never waits) If R is older than H, R waits If R is younger than H it dies, restarts 2.Wound/wait algorithm: (Older process never waits) If R is older than H, resources is preempted (which may mean process is killed, restarted) If R is younger than H, R waits Restarted process keeps old timestamp

Comparison of deadlock avoidance schemes Wound/wait and wait/die kill processes even when there is no deadlock (more aggressive). Wait/die generally kills more processes than wound/wait, but generally at an earlier stage Note: Wait/die and Wound/wait are sometimes classified as prevention schemes rather than avoidance schemes CompSci 143aSpring,

CompSci 143a Spring, Deadlock Prevention Deadlock requires the following conditions: –Mutual exclusion: Resources not sharable –Hold and wait: Process must be holding one resource while requesting another –Circular wait: At least 2 processes must be blocked on each other

CompSci 143a Spring, Deadlock Prevention Eliminate mutual exclusion: –Not possible in most cases –Spooling makes I/O devices sharable Eliminate hold-and-wait –Request all resources at once –Release all resources before a new request –Release all resources if current request blocks Eliminate circular wait –Order all resources: SEQ(R i )  SEQ(R j ) –Process must request in ascending order

CompSci 143a Spring, History Originally developed by Steve Franklin Modified by Michael Dillencourt, Summer, 2007 Modified by Michael Dillencourt, Spring, 2009 Modified by Michael Dillencourt, Winter, 2010