1 Deadlock. 2 Concurrency Issues Past lectures:  Problem: Safely coordinate access to shared resource  Solutions:  Use semaphores, monitors, locks,

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Lecture 7: Deadlocks, Deadlock Risk Management. Lecture 7 / Page 2AE4B33OSS Silberschatz, Galvin and Gagne ©2005 Contents The Concept of Deadlock Resource-Allocation.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 8: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks.
Chapter 7. Deadlocks.
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.
Deadlock CSCI 444/544 Operating Systems Fall 2008.
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Deadlock and Starvation Deadlock – two or more processes are waiting indefinitely for.
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.
What we will cover…  The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock.
Concurrency: Deadlock and Starvation Chapter 6. Goal and approach Deadlock and starvation Underlying principles Solutions? –Prevention –Detection –Avoidance.
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.
Chapter 7 – Deadlock (Pgs 283 – 306). Overview  When a set of processes is prevented from completing because each is preventing the other from accessing.
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.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
CS6502 Operating Systems - Dr. J. Garrido Deadlock – Part 2 (Lecture 7a) CS5002 Operating Systems Dr. Jose M. Garrido.
 The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock Avoidance  Deadlock.
Dr. Kalpakis CMSC 421, Operating Systems Deadlocks.
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.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks System Model Deadlock Characterization Methods.
Mi-Jung Choi Dept. of Computer and Science Silberschatz, Galvin and Gagne ©2006 Operating System Principles Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 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.
Chapter 7: Deadlocks. 7.2CSCI 380 – Operating Systems Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization Methods for Handling.
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.
Chap 7 Deadlocks. Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks To.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 6 Deadlocks Slide 1 Chapter 6 Deadlocks.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 7: Deadlocks.
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:=
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.
7.1 CSE Department MAITSandeep Tayal 7: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
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 - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The 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.
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
Process Management Deadlocks.
Chapter 7: Deadlocks.
CSE 120 Principles of Operating
Concurrency: Deadlock and Starvation
Chapter 7 Deadlocks.
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 7: Deadlocks.
CSc 552 Advanced Unix Process deadlock deadlock prevention
CS 333 Introduction to Operating Systems Class 7 - Deadlock
Chapter 7: Deadlocks.
Don Porter Portions courtesy Emmett Witchel
Presentation transcript:

1 Deadlock

2 Concurrency Issues Past lectures:  Problem: Safely coordinate access to shared resource  Solutions:  Use semaphores, monitors, locks, condition variables  Coordinate access within shared objects What about coordinated access across multiple objects?  If you are not careful, it can lead to deadlock Today’s lecture:  What is deadlock?  How can we address deadlock?

3 Deadlocks Motivating Examples Two producer processes share a buffer but use a different protocol for accessing the buffers A postscript interpreter and a visualization program compete for memory frames Producer1() { P(emptyBuffer) P(producerMutexLock) : } Producer1() { P(emptyBuffer) P(producerMutexLock) : } Producer2(){ P(producerMutexLock) P(emptyBuffer) : } Producer2(){ P(producerMutexLock) P(emptyBuffer) : } PS_Interpreter() { request(memory_frames, 10) request(frame_buffer, 1) } PS_Interpreter() { request(memory_frames, 10) request(frame_buffer, 1) } Visualize() { request(frame_buffer, 1) request(memory_frames, 20) } Visualize() { request(frame_buffer, 1) request(memory_frames, 20) }

4 The TENEX Case If a process requests all systems buffers, operator console tries to print an error message To do so  lock the console  request a buffer DUH!

5 Deadlock Definition A set of processes is deadlocked when every process in the set is waiting for an event that can only be generated by some process in the set Starvation vs. deadlock  Starvation: threads wait indefinitely (e.g., because some other thread is using a resource)  Deadlock: circular waiting for resources  Deadlock  starvation, but not the other way Running Ready Waiting Head Tail ready queue Head Tail semaphore/ condition queues

6 A Graph Theoretic Model of Deadlock The resource allocation graph (RAG) Basic components of any resource allocation problem  Processes and resources Model the state of a computer system as a directed graph  G = (V, E)  V = the set of vertices = {P 1,..., P n }  {R 1,..., R m } PiPi PkPk request edge allocation edge RjRj PiPi RjRj  E = the set of edges = {edges from a resource to a process}  {edges from a process to a resource}

7 Resource Allocation Graphs Examples A PostScript interpreter that is waiting for the frame buffer lock and a visualization process that is waiting for memory V = {PS interpret, visualization}  {memory frames, frame buffer lock} Visualization Process Memory Frames Frame Buffer PostScript Interpreter

8 A Graph Theoretic Model of Deadlock Resource allocation graphs & deadlock Theorem: If a resource allocation graph does not contain a cycle then no processes are deadlocked Visualization Process Memory Frames Frame Buffer PostScript Interpreter A cycle in a RAG is a necessary condition for deadlock Is the existence of a cycle a sufficient condition? Game

9 A Graph Theoretic Model of Deadlock Resource allocation graphs & deadlock Theorem: If there is only a single unit of all resources then a set of processes are deadlocked iff there is a cycle in the resource allocation graph Visualization Process Memory Frames Frame Buffer PostScript Interpreter

10 Using the Theory An operational definition of deadlock A set of processes are deadlocked iff the following conditions hold simultaneously 1.Mutual exclusion is required for resource usage (serially useable) 2.A process is in a “hold-and-wait” state 3.Preemption of resource usage is not allowed 4.Circular waiting exists (a cycle exists in the RAG) Visualization Process Memory Frames Frame Buffer PostScript Interpreter

11 Dealing With Deadlock Deadlock prevention & avoidance Adopt some resource allocation protocol that ensures deadlock can never occur  Deadlock prevention/avoidance  Guarantee that deadlock will never occur  Generally breaks one of the following conditions:  Mutex  Hold-and-wait  No preemption  Circular wait *This is usually the weak link*  Deadlock detection and recovery  Admit the possibility of deadlock occurring and periodically check for it  On detecting deadlock, abort  Breaks the no-preemption condition What does the RAG for a lock look like?

12 Deadlock Avoidance Resource Ordering Recall this situation. How can we avoid it? Producer1() { P(emptyBuffer) P(producerMutexLock) : } Producer1() { P(emptyBuffer) P(producerMutexLock) : } Producer2(){ P(producerMutexLock) P(emptyBuffer) : } Producer2(){ P(producerMutexLock) P(emptyBuffer) : } Eliminate circular waiting by ordering all locks (or semaphores, or resoruces). All code grabs locks in a predefined order. Problems?  Maintaining global order is difficult, especially in a large project.  Global order can force a client to grab a lock earlier than it would like, tying up a resource for too long.  Deadlock is a global property, but lock manipulation is local.

13 Deadlock Detection & Recovery Recovering from deadlock Abort all deadlocked processes & reclaim their resources Abort one process at a time until all cycles in the RAG are eliminated Where to start?  Select low priority process  Processes with most allocation of resources Caveat: ensure that system is in consistent state (e.g., transactions) Optimization:  Checkpoint processes periodically; rollback processes to checkpointed state P4P4 P1P1 P2P2 P3P3 P5P5 P5P5 R1R1 R2R2 R3R3 R4R4

14  resource allocation state matrix Dealing With Deadlock Deadlock avoidance Examine each resource request and determine whether or not granting the request can lead to deadlock R 1 R 2 R 3... R r P1P2P3 PpP1P2P3 Pp n 1,1 n 1,2 n 1,3... n 1,r n 2,1 n 3,1 n p,1 np,rnp,r n 2,2... Define a set of vectors and matrices that characterize the current state of all resources and processes  maximum claim matrix Max ij = the maximum number of units of resource j that the process i will ever require simultaneously  available vector Alloc ij = the number of units of resource j held by process i Avail j = the number of units of resource j that are unallocated

15 Dealing With Deadlock Deadlock detection & recovery What are some problems with the banker’s algorithm?  Very slow O(n 2 m)  Too slow to run on every allocation. What else can we do? Deadlock prevention and avoidance:  Develop and use resource allocation mechanisms and protocols that prohibit deadlock Deadlock detection and recovery:  Let the system deadlock and then deal with it Detect that a set of processes are deadlocked Recover from the deadlock