Deadlocks. 2 System Model There are non-shared computer resources –Maybe more than one instance –Printers, Semaphores, Tape drives, CPU Processes need.

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

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.
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 8 Deadlocks.
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.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
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.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
What we will cover…  The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock.
Deadlock Characterization
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Deadlocks.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
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.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-6 Deadlocks Department of Computer Science and Software Engineering.
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  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 28 Handling Deadlock.
 The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock Avoidance  Deadlock.
Operating Systems (CS 340 D) Dr. Abeer Mahmoud Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Chapter 7 Deadlocks Page 2 Chapter 7: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
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.
CS333 Intro to Operating Systems Jonathan Walpole.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
Deadlocks: Part I Prevention and Avoidance. 2 Review: Dining Philosopher’s Dijkstra –A problem that was invented to illustrate a different aspect of communication.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 7 Operating Systems.
Chapter 7: Deadlocks. 7.2CSCI 380 – Operating Systems Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization Methods for Handling.
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.
CS307 Operating Systems Deadlocks Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2012.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 6 Deadlocks Slide 1 Chapter 6 Deadlocks.
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.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 7: Deadlocks.
Deadlock A deadlock is a situation wherein two or more competing actions are waiting for the other to finish, and thus neither ever does. Example : “When.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
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.
OPERATING SYSTEM CONCEPTS AND PRACTISE
Chapter 7: Deadlocks.
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks.
Operating System: DEADLOCKS
Chapter 7 Deadlocks.
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 1/11/2019 B.Ramamurthy.
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 2/23/2019 B.Ramamurthy.
Deadlocks Session - 13.
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 4/23/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 5/1/2019 B.Ramamurthy.
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 8/28/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 9/3/2019 B.Ramamurthy.
Presentation transcript:

Deadlocks

2 System Model There are non-shared computer resources –Maybe more than one instance –Printers, Semaphores, Tape drives, CPU Processes need access to these resources –Acquire resource If resource is available, access is granted If not available, the process is blocked –Use resource –Release resource Undesirable scenario: –Process A acquires resource 1, and is waiting for resource 2 –Process B acquires resource 2, and is waiting for resource 1  Deadlock!

3 For example: Semaphores semaphore: mutex1 = 1 /* protects resource 1 */ mutex2 = 1 /* protects resource 2 */ Process A code: { /* initial compute */ P(mutex1) P(mutex2) /* use both resources */ V(mutex2) V(mutex1) } Process B code: { /* initial compute */ P(mutex2) P(mutex1) /* use both resources */ V(mutex2) V(mutex1) }

4 Deadlocks Definition: Deadlock exists among a set of processes if –Every process is waiting for an event –This event can be caused only by another process in the set Event is the acquire of release of another resource One-lane bridge

5 Four Conditions for Deadlock Coffman et. al Necessary conditions for deadlock to exist: –Mutual Exclusion At least one resource must be held is in non-sharable mode –Hold and wait There exists a process holding a resource, and waiting for another –No preemption Resources cannot be preempted –Circular wait There exists a set of processes {P 1, P 2, … P N }, such that –P 1 is waiting for P 2, P 2 for P 3, …. and P N for P 1 All four conditions must hold for deadlock to occur

6 Resource Allocation Graph Deadlock can be described using a resource allocation graph, RAG The RAG consists of: –set of vertices V = P  R, where P={P 1,P 2,…,P n } of processes and R={R 1,R 2,…,R m } of resources. –Request edge: directed edge from a process to a resource, P i  R j, implies that P i has requested R j. –Assignment edge: directed edge from a resource to a process, R j  P i, implies that R j has been allocated to P i. If the graph has no cycles, deadlock cannot exist. If the graph has a cycle, deadlock may exist.

7 RAG Example R1R3 R4 R2 P3P2 P1 R1 P1P2P3 P4 R2R4 Cycles: P1-R1-P2-R3-P3-R2-P1 P2-R3-P3-R2-P2 and there is deadlock. Same cycles, but no deadlock

8 Dealing with Deadlocks Proactive Approaches: –Deadlock Prevention Negate one of 4 necessary conditions Prevent deadlock from occurring –Deadlock Avoidance Carefully allocate resources based on future knowledge Deadlocks are prevented Reactive Approach: –Deadlock detection and recovery Let deadlock happen, then detect and recover from it Ignore the problem –Pretend deadlocks will never occur –Ostrich approach

9 Deadlock Prevention Can the OS prevent deadlocks? Prevention: Negate one of necessary conditions –Mutual exclusion: Make resources sharable Not always possible (spooling?) –Hold and wait Do not hold resources when waiting for another  Request all resources before beginning execution Processes do not know what all they will need Starvation (if waiting on many popular resources) Low utilization (Need resource only for a bit) Alternative: Release all resources before requesting anything new –Still has the last two problems

10 Deadlock Prevention Prevention: Negate one of necessary conditions –No preemption: Make resources preemptable (2 approaches) Preempt requesting processes’ resources if all not available Preempt resources of waiting processes to satisfy request Good when easy to save and restore state of resource –CPU registers, memory virtualization –Circular wait: (2 approaches) Single lock for entire system? (Problems) Impose partial ordering on resources, request them in order

11 Breaking Circular Wait Order resources (lock1, lock2, …) Acquire resources in strictly increasing/decreasing order When requests to multiple resources of same order: –Make the request a single operation Intuition: Cycle requires an edge from low to high, and from high to low numbered node, or to same node Ordering not always possible, low resource utilization

12 Acquire all resources, if block on any, release all, and retry Pro: dynamic, simple, flexible Con: –Cost with number of resources? –Length of critical section? –Hard to know what’s needed a priori Two phase locking print_file: lock(file); acquire printer acquire disk; …do work… release all

13 Deadlock Avoidance If we have future information –Max resource requirement of each process before they execute Can we guarantee that deadlocks will never occur? Avoidance Approach: –Before granting resource, check if state is safe –If the state is safe  no deadlock!

14 Safe State A state is said to be safe, if it has a process sequence {P 1, P 2,…, P n }, such that for each P i, the resources that P i can still request can be satisfied by the currently available resources plus the resources held by all P j, where j < i State is safe because OS can definitely avoid deadlock –by blocking any new requests until safe order is executed This avoids circular wait condition –Process waits until safe state is guaranteed

15 Safe State Example Suppose there are 12 tape drives max need current usage could ask for p01055 p1422 p drives remain current state is safe because a safe sequence exists: p1 can complete with current resources p0 can complete with current+p1 p2 can complete with current +p1+p0 if p2 requests 1 drive, then it must wait to avoid unsafe state.

16 Safe State Example (One resource class only) process holding max claims A 4 6 B 4 11 C 2 7 unallocated: 2 safe sequence: A,C,B If C should have a claim of 9 instead of 7, there is no safe sequence.

17 Safe State Example process holding max claims A 4 6 B 4 11 C 2 9 unallocated: 2 deadlock-free sequence: A,C,B if C makes only 6 requests However, this sequence is not safe: If C should have 7 instead of 6 requests, deadlock exists.

18 RAG Algorithm Works if only one instance of each resource type Algorithm: –Add a claim edge, P i  R j if P i can request R j in the future Represented by a dashed line in graph –A request P i  R j can be granted only if: Adding an assignment edge R j  P i does not introduce cycles –Since cycles imply unsafe state R1 P1P2 R2 R1 P1P2 R2