Deadlock Detection & recovery. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

Similar documents
Deadlock and Starvation

CSE Opera+ng System Principles

Deadlocks. Deadlock Overview

The Deadlock Problem

Chapter 7: Deadlocks

CS307: Operating Systems

Deadlock. Concepts to discuss. A System Model. Deadlock Characterization. Deadlock: Dining-Philosophers Example. Deadlock: Bridge Crossing Example

Chapter 8: Deadlocks

Chapter 8: Deadlocks. The Deadlock Problem. System Model. Bridge Crossing Example. Resource-Allocation Graph. Deadlock Characterization

Chapter 7: Deadlocks. Operating System Concepts 8 th Edition,

Chapter 7: Deadlocks. Chapter 7: Deadlocks. The Deadlock Problem. Chapter Objectives. System Model. Bridge Crossing Example

Chapter 7 : 7: Deadlocks Silberschatz, Galvin and Gagne 2009 Operating System Concepts 8th Edition, Chapter 7: Deadlocks

The Deadlock Problem (1)

Chapter 7: Deadlocks

Chapter 8: Deadlocks. Bridge Crossing Example. The Deadlock Problem

Chapter 7: Deadlocks. Operating System Concepts with Java 8 th Edition

Module 7: Deadlocks. The Deadlock Problem. Bridge Crossing Example. System Model

Chapter 8: Deadlocks. The Deadlock Problem

Chapter 7: Deadlocks

Chapter 7: Deadlocks

When Deadlock Happens

Module 7: Deadlocks. The Deadlock Problem

Module 7: Deadlocks. System Model. Deadlock Characterization. Methods for Handling Deadlocks. Deadlock Prevention. Deadlock Avoidance

Bridge Crossing Example

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Deadlocks. Minsoo Ryu. Real-Time Computing and Communications Lab. Hanyang University.

Operating Systems 2015 Spring by Euiseong Seo DEAD LOCK

The Slide does not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams.

CMSC 412. Announcements

Chapter 8: Deadlocks. Operating System Concepts with Java

Deadlock Risk Management

Deadlocks. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CS370 Operating Systems

Module 6: Deadlocks. Reading: Chapter 7

Chapter 8: Deadlocks. The Deadlock Problem

The Deadlock Problem. Chapter 8: Deadlocks. Bridge Crossing Example. System Model. Deadlock Characterization. Resource-Allocation Graph

Principles of Operating Systems

CS307 Operating Systems Deadlocks

Deadlocks. Bridge Crossing Example. The Problem of Deadlock. Deadlock Characterization. Resource-Allocation Graph. System Model

Deadlock Risk Management

Lecture 7 Deadlocks (chapter 7)

UNIT-5 Q1. What is deadlock problem? Explain the system model of deadlock.

Deadlock Prevention. Restrain the ways request can be made. Mutual Exclusion not required for sharable resources; must hold for nonsharable resources.

Chapter 7: Deadlocks CS370 Operating Systems

Roadmap. Safe State. Deadlock Avoidance. Basic Facts. Safe, Unsafe, Deadlock State. Tevfik Koşar. CSC Operating Systems Spring 2007

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

CHAPTER 7: DEADLOCKS. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

Principles of Operating Systems

Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - X Deadlocks - I. University at Buffalo. Synchronization structures

Roadmap. Problems with Semaphores. Semaphores. Monitors. Monitor - Example. Tevfik Koşar. CSE 421/521 - Operating Systems Fall 2012

Deadlocks. Prepared By: Kaushik Vaghani

Chapter 7: Deadlocks. Operating System Concepts 8 th Edition,

Silberschatz, Galvin and Gagne 2013! CPU cycles, memory space, I/O devices! " Silberschatz, Galvin and Gagne 2013!

Chapter 7: Deadlocks. Operating System Concepts 9th Edition DM510-14

Chapter 7: Deadlocks. Operating System Concepts 8 th Edition,! Silberschatz, Galvin and Gagne 2009!

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

The Deadlock Problem

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition! Silberschatz, Galvin and Gagne 2013!

CS370 Operating Systems

Deadlocks. Copyright : University of Illinois CS 241 Staff 1

The Deadlock Problem. A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.

Chapter 8: Deadlocks. The Deadlock Problem

Deadlock and Starvation

ICS Principles of Operating Systems. Lectures Set 5- Deadlocks Prof. Nalini Venkatasubramanian

CS370 Operating Systems

Deadlocks. Operating System Concepts - 7 th Edition, Feb 14, 2005

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Deadlocks. Dr. Yingwu Zhu

The Deadlock Problem

System Model. Types of resources Reusable Resources Consumable Resources

CSC Operating Systems Fall Lecture - XII Deadlocks - III. Tevfik Ko!ar. Louisiana State University. October 6 th, 2009

Chapter 7: Deadlocks. Operating System Concepts 8th Edition, modified by Stewart Weiss

Chapter - 4. Deadlocks Important Questions

CS420: Operating Systems. Deadlocks & Deadlock Prevention

CHAPTER 7 - DEADLOCKS

COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 7 Deadlocks. Zhi Wang Florida State University

Deadlock. Disclaimer: some slides are adopted from Dr. Kulkarni s and book authors slides with permission 1

The deadlock problem

Unit-03 Deadlock and Memory Management Unit-03/Lecture-01

OPERATING SYSTEMS. Deadlocks

Deadlocks: Part I Prevention and Avoidance Yi Shi Fall 2017 Xi an Jiaotong University

CSCC 69H3 2/1/13. Today: Deadlock. Remember example from last week? Example of Deadlock. Example: dining philosophers: Not just an OS Problem!

Basic concepts and Terminologies

Last Class: Synchronization Problems!

Deadlocks. Deadlock in Resource Sharing Environment. CIT 595 Spring Recap Example. Representing Deadlock

Chapter 7: Deadlocks

Resource Allocation and Deadlock Handling

Lecture Topics. Announcements. Today: Concurrency (Stallings, chapter , 5.7) Next: Exam #1. Self-Study Exercise #5. Project #3 (due 9/28)

CSC 539: Operating Systems Structure and Design. Spring 2005

Back to synchronization

Concurrency: Deadlock and Starvation. Chapter 6

Yet another synchronization problem

COMP 3713 Operating Systems Slides Part 3. Jim Diamond CAR 409 Jodrey School of Computer Science Acadia University

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

Chapter 7: Deadlocks. Chapter 7: Deadlocks. System Model. Chapter Objectives

TDDB68 + TDDD82. Lecture: Deadlocks

Lecture 3: Synchronization & Deadlocks

Chapter 7: Deadlocks. Chapter 7: Deadlocks. Deadlock Example. Chapter Objectives

Contents. Chapter 8 Deadlocks

Transcription:

Deadlock Detection & recovery CSSE 332 Operating Systems Rose-Hulman Institute of Technology

The deadlock problem A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set Example System has 2 disk drives P1 and P2 each holds one disk drive and each needs another one Example semaphores A and B, initialized to 1

Approaches to deadlock handling Ignore Deadlock (Ostrich approach) If infrequent enough and result is not serious Used by most operating systems, including UNIX Deadlock Prevention Prevent one of the necessary/sufficient conditions Deadlock Avoidance Allow the 3 necessary conditions Dynamically make choices to avoid deadlock decide based on knowledge of future requests i.e., find a safe path

Approaches to deadlock handling Deadlock Detection Periodically run algorithm to detect circular waiting After detecting deadlock, run a recovery algorithm to remove deadlock

Deadlock Humor Two drivers were approaching a one- lane bridge. They reached the middle of the bridge at the same time, forcing a confrontation. They got out of their cars and went nose to nose. One driver said, I don t back up for idiots. The other driver calmly got back in his car and started backing up. He said, No problem - - - I do. (Deitel et al) Moral of the story: Processes are neither stubborn nor co- operative, so deadlock is a painful experience at best. Usually, one or more processes will have to be backed out of the deadlock, losing some or all of their work.

Deadlock detec8on and recovery Allow system to enter deadlock state Detection algorithm Recovery scheme Q1

Single Instance of Each Resource Type Maintain wait-for graph" Nodes are processes" P i P j if P i is waiting for P j " Periodically invoke an algorithm that searches for a cycle in the graph. If there is a cycle, there exists a deadlock!" " An algorithm to detect a cycle in a graph requires an order of n 2 operations, where n is the number of vertices in the graph"

RAG and Wait-for Graph Resource-Allocation Graph" Corresponding wait-for graph"

Multiple Instances of a Resource Type Available: A vector of length m indicates the number of available resources of each type. " Allocation: An n x m matrix defines the number of resources of each type currently allocated to each process. " Request: An n x m matrix indicates the current request of each process. If Request [i j ] = k, then process P i is requesting k more instances of resource type R j."

Detection Algorithm 1."Let Work and Finish be vectors of length m and n, respectively Initialize:" (a) Work = Available" (b)"for i = 1,2,, n, if Allocation i 0, then Finish[i] = false; otherwise, Finish[i] = true" 2."Find an index i such that both:" (a)"finish[i] == false" (b)"request i Work " If no such i exists, go to step 4"

Detection Algorithm (Cont.) 3."Work = Work + Allocation i Finish[i] = true go to step 2 " 4."If Finish[i] == false, for some i, 1 i n, then the system is in deadlock state. Moreover, if Finish[i] == false, then P i is deadlocked" "" Algorithm requires an order of O(m x n 2) operations to detect whether the system is in deadlocked state"

Example of Detection Algorithm Five processes P 0 through P 4 ; three resource types A (7 instances), B (2 instances), and C (6 instances)" Snapshot at time T 0 :" " " " Allocation " "Request "Available" " " "A B C " A B C " "A B C" " "P 0 " 0 1 0 0 0 0 " "0 0 0" " "P 1 2 0 0 " 2 0 2" " "P 2 " 3 0 3 0 0 0 " " "P 3 2 1 1 " 1 0 0 " " "P 4 0 0 2 " 0 0 2" Is the system in a deadlock state?" "

Example (Cont.) P 2 requests an additional instance of type C" " " "Request" " " "A B C" " " P 0 "0 0 0" " " P 1 "2 0 2" " "P 2 "0 0 1" " "P 3 "1 0 0 " " "P 4 "0 0 2" State of system?"

Detection-Algorithm Usage When, and how often, to invoke depends on:" How often a deadlock is likely to occur?" How many processes will need to be rolled back?" one for each disjoint cycle " If detection algorithm is invoked arbitrarily, there may be many cycles in the resource graph and so we would not be able to tell which of the many deadlocked processes caused the deadlock"

Recovery: Process Termina8on Abort all deadlocked processes Abort one process at a time until no deadlock In which order should we choose to abort? Priority of the process. How long process has computed, and how much longer to completion. Resources the process has used. Resources process needs to complete. How many processes will need to be terminated? Is process interactive or batch?

Recovery: Resource Preemp8on Selecting a victim minimize cost Rollback return to some safe state, restart process from that state Starvation same process may always be picked as victim include number of rollback in cost factor

Deadlock should not be ignored A real- time control system monitoring a gasoline refinery Need to ensures the safe and proper operation of the refinery An avoidance strategy or prevention strategy must be employed A computerized pacemaker Can t afford to miss a single beat Deadlock avoidance or prevention must be employed Q6

Deadlock should not be ignored Embedded systems cell phones, PDAs. These are SoCs or system on chips i.e. everything is on one chip and SoCs are characterized by a small set of resources and real- time processing constraints. Can t have a system administrator come in and decide which process to kill after deadlock has been detected. Either a prevention or avoidance strategy must be employed.

Dining Philosopher Problem Five philosophers who alternately think and eat Share a fork with each neighbor Assume each philosopher picks up left fork, then right fork, then eats Deadlock if all are hungry at the same time

Solu8ons: Dining Philosophers Problem Buy more Forks Equivalent to increasing resources Put fork down if 2nd fork busy Can produce livelock if philosophers stay synchronized Room Attendant Only let 4 of the philosophers into the room at once May have 4 philosophers in room, but only 1 might eat Mix order of grabbing forks Some grab forks in the other order (right fork, then left fork) Any mix will avoid deadlock

Correct solu8on with semaphores semaphore fork[5] = {1, 1, 1, 1, 1; semaphore room = 4; process philosopher(int i) { while(true) { think(); wait (room); wait(fork[i]); wait(fork[(i+1) mod 5]); eat(); signal(fork[(i+1) mod 5]); signal(fork[i]); signal (room); void main() { int i; for (i =0; i < 5; i++) { philosopher(i);

Incorrect solu8on with semaphores semaphore fork[5] = {1,1,1,1,1; process philosopher(int i){ while(true){ think(); wait(fork[i]); wait(fork[(i+1)mod5]); eat(); signal(fork[(i+1)mod5]); signal(fork[i]); void main() { int i; for (i =0; i < 5; i++) { philosopher(i);

Another incorrect solu8on binary semaphore x = 1; process philosopher(int i){ while(true){ think(); wait(x); pick up fork[i]; pick up fork[(i+1)mod5]; signal(x); eat(); wait(x); return fork[i] ; return fork[(i+1)mod5] ; signal(x); void main() { int I; for (i =0; i < 5; i++) { philosopher(i);