DPNM Lab. Dept. of CSE, POSTECH

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Chapter 7: Deadlocks Adapted by Donghui Zhang from the original version by Silberschatz et al.
Deadlock Prevention, Avoidance, and Detection.  The Deadlock problem The Deadlock problem  Conditions for deadlocks Conditions for deadlocks  Graph-theoretic.
DEADLOCK. Contents  Principles of deadlock  Deadlock prevention  Deadlock detection.
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.
5/25/2015Page 1 Deadlock Management B. Ramamurthy.
Chapter 3 Deadlocks - Αδιέξοδα 3.1. Resource
Avishai Wool lecture Introduction to Systems Programming Lecture 5 Deadlocks.
DPNM Lab. Dept. of CSE, POSTECH
Deadlock Chapter 3 R1 R2 P2P1 Allocated Requested.
Chapter 7: Deadlocks. 7.2 Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Deadlocks.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 8: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks.
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 Deadlock Definition of deadlock Condition for its occurrence Solutions for avoiding and breaking deadlock –Deadlock Prevention –Deadlock Avoidance –Deadlock.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
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.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All.
CS6502 Operating Systems - Dr. J. Garrido Deadlock – Part 2 (Lecture 7a) CS5002 Operating Systems Dr. Jose M. Garrido.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
Deadlocks System Model RAG Deadlock Characterization
Mi-Jung Choi Dept. of Computer and Science Silberschatz, Galvin and Gagne ©2006 Operating System Principles Chapter 7: Deadlocks.
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.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model 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.
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);
Sistem Operasi IKH311 Deadlock. 2 Resources Examples of computer resources printers tape drives tables Processes need access to resources in reasonable.
Thursday, February 23, 2012 Chapter 6 homework questions?
Chapter 7: Deadlocks.
OPERATING SYSTEM CONCEPTS AND PRACTISE
Chapter 7: Deadlocks.
Deadlock Management.
Deadlocks References text: Tanenbaum ch.3.
Chapter 7: Deadlocks.
Operating System: DEADLOCKS
Chapter 7 Deadlocks.
Chapter 7: Deadlocks.
Process Deadlocks.
Deadlocks References text: Tanenbaum ch.3.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
G.Anuradha Ref:- Galvin
Chapter 7: Deadlocks.
Outline Deadlocks, dead lock prevention, avoidance.
Review: Readers-Writers Problem
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Deadlocks Session - 13.
DEADLOCK.
Chapter 7: Deadlocks.
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
Chapter 7: Deadlocks.
Deadlocks References text: Tanenbaum ch.3.
Chapter 7: Deadlocks.
Chapter 8: Deadlocks Deadlock Characterization
Presentation transcript:

DPNM Lab. Dept. of CSE, POSTECH ITEC 502 컴퓨터 시스템 및 실습 Chapter 4-1: Deadlock Mi-Jung Choi mjchoi@postech.ac.kr DPNM Lab. Dept. of CSE, POSTECH

Contents Resource Introduction to deadlocks Deadlock modeling The ostrich algorithm Deadlock detection and recovery ITEC502 컴퓨터 시스템 및 실습

Resources (1) Examples of computer resources printers tape drives tables Processes need access to resources in reasonable order Suppose a process holds resource A and requests resource B at same time another process holds B and requests A both are blocked and remain so ITEC502 컴퓨터 시스템 및 실습

Resources (2) Deadlocks occur when … Preemptable resources processes are granted exclusive access to devices we refer to these devices generally as resources Preemptable resources can be taken away from a process with no ill effects Nonpreemptable resources will cause the process to fail if taken away ITEC502 컴퓨터 시스템 및 실습

Resources (3) Sequence of events required to use a resource request the resource use the resource release the resource Must wait if request is denied requesting process may be blocked may fail with error code ITEC502 컴퓨터 시스템 및 실습

Introduction to Deadlocks Formal definition: A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set can cause or A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set Usually the event is release of a currently held resource None of the processes can … run release resources be awakened ITEC502 컴퓨터 시스템 및 실습

Deadlock Example Example P0 P1 System has 2 tape drives P1 and P2 each hold one tape drive and each needs another one semaphores A and B, initialized to 1 P0 P1 wait (A); wait (B); wait (B); wait (A); ITEC502 컴퓨터 시스템 및 실습

Four Conditions for Deadlock Mutual exclusion condition each resource assigned to 1 process or is available Hold and wait condition process holding resources can request additional No preemption condition previously granted resources cannot forcibly taken away Circular wait condition must be a circular chain of 2 or more processes each is waiting for resource held by next member of the chain Deadlock can arise if four conditions hold simultaneously ITEC502 컴퓨터 시스템 및 실습

Resource-Allocation Graph (1) Deadlocks can be described more precisely in terms of a directed graph called a system resource-allocation graph: A set of vertices V and a set of edges E V is partitioned into two types: P = {P1, P2, …, Pn}, the set consisting of all the processes in the system R = {R1, R2, …, Rm}, the set consisting of all resource types in the system E is partitioned into two types: request edge – directed edge Pi  Rj assignment edge – directed edge Rj  Pi ITEC502 컴퓨터 시스템 및 실습

Resource-Allocation Graph (2) Process Resource Type with 4 instances Pi requests a instance of Rj Pi is holding an instance of Rj Pi Rj Pi Rj ITEC502 컴퓨터 시스템 및 실습

Resource-Allocation Graph (3) Modeled with directed graphs Resource R assigned to process A Process B is requesting/waiting for resource S Process C and D are in deadlock over resources T and U ITEC502 컴퓨터 시스템 및 실습

Example of a Resource Allocation Graph Deadlock or not? Mutual Exclusion R1, R2, R3, R4 Hold and Wait P1, P2 No Preemption YES Circular Wait NO ITEC502 컴퓨터 시스템 및 실습

Resource Allocation Graph With a Deadlock Deadlock or not? Mutual Exclusion R1, R2, R3, R4 Hold and Wait P1, P2 , P3 No Preemption YES Circular Wait ITEC502 컴퓨터 시스템 및 실습

Resource Allocation Graph With A Cycle But No Deadlock Deadlock or not? Mutual Exclusion R1, R2 Hold and Wait P1, P3 No Preemption YES Circular Wait ITEC502 컴퓨터 시스템 및 실습

Deadlock Modeling (1) A B C How deadlock occurs ITEC502 컴퓨터 시스템 및 실습

How deadlock can be avoided Deadlock Modeling (2) (o) (p) (q) How deadlock can be avoided ITEC502 컴퓨터 시스템 및 실습

Strategies for dealing with Deadlocks just ignore the problem altogether Ignore the problem and pretend that deadlocks never occur in the system; used by most operating systems, including UNIX and Windows It is then up to the application developer to write programs that handle deadlocks detection and recovery Allow the system to enter a deadlock state and then recover deadlock detection, deadlock recovery dynamic avoidance careful resource allocation prevention negating one of the four necessary conditions ensure that the system will never enter a deadlock state Use a protocol to prevent or avoid deadlocks ITEC502 컴퓨터 시스템 및 실습

The Ostrich Algorithm Pretend there is no problem Reasonable if deadlocks occur very rarely cost of prevention is high UNIX and Windows takes this approach It is a trade off between convenience correctness ITEC502 컴퓨터 시스템 및 실습

Deadlock Detection Allow system to enter deadlock state Detection algorithm Recovery scheme ITEC502 컴퓨터 시스템 및 실습

Detection with One Resource of Each Type (1) Note the resource ownership and requests A cycle can be found within the graph, denoting deadlock ITEC502 컴퓨터 시스템 및 실습

Detection with One Resource of Each Type (2) Data structures needed by deadlock detection algorithm ITEC502 컴퓨터 시스템 및 실습

Detection with One Resource of Each Type (3) An example for the deadlock detection algorithm ITEC502 컴퓨터 시스템 및 실습

Recovery from Deadlock (1) When a detection algorithm determines that a deadlock exists, several alternatives are available: To inform the operator that a deadlock has occurred and to let the operator deal with the deadlock manually Recovery through preemption To preempt some resources from one or more of the deadlocked processes take a resource from some other process depends on nature of the resource Recovery through rollback checkpoint a process periodically use this saved state restart the process if it is found deadlocked ITEC502 컴퓨터 시스템 및 실습

Recovery from Deadlock (2) Three issues in resource preemption 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 ITEC502 컴퓨터 시스템 및 실습

Recovery from Deadlock (3) Recovery through killing processes = process termination to abort one or more processes to break the circular wait crudest but simplest way to break a deadlock kill one of the processes in the deadlock cycle the other processes get its resources choose process that can be rerun from the beginning 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? ITEC502 컴퓨터 시스템 및 실습

Summary A deadlock state occurs when two or more processes are waiting indefinitely for an event that can be caused only by one of the waiting processes A deadlock requires that four conditions hold simultaneously Mutual exclusion, hold and wait, no preemption, circular wait Four principle methods for dealing with deadlocks Deadlock prevention Deadlock avoidance Deadlock detection-recovery scheme Ignore the deadlock problem Deadlock prevention ensures that at least one of the necessary conditions never holds When deadlock is detected, the system must recover either by terminating some of the deadlocked processes or by preempting resources from some of the deadlocked processes ITEC502 컴퓨터 시스템 및 실습

Review Resource Introduction to deadlocks Deadlock modeling The ostrich algorithm Deadlock detection and recovery ITEC502 컴퓨터 시스템 및 실습