Download presentation
Presentation is loading. Please wait.
1
DPNM Lab. Dept. of CSE, POSTECH
ITEC 502 컴퓨터 시스템 및 실습 Chapter 4-1: Deadlock Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH
2
Contents Resource Introduction to deadlocks Deadlock modeling
The ostrich algorithm Deadlock detection and recovery ITEC502 컴퓨터 시스템 및 실습
3
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 컴퓨터 시스템 및 실습
4
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 컴퓨터 시스템 및 실습
5
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 컴퓨터 시스템 및 실습
6
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 컴퓨터 시스템 및 실습
7
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 컴퓨터 시스템 및 실습
8
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 컴퓨터 시스템 및 실습
9
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 컴퓨터 시스템 및 실습
10
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 컴퓨터 시스템 및 실습
11
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 컴퓨터 시스템 및 실습
12
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 컴퓨터 시스템 및 실습
13
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 컴퓨터 시스템 및 실습
14
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 컴퓨터 시스템 및 실습
15
Deadlock Modeling (1) A B C How deadlock occurs ITEC502 컴퓨터 시스템 및 실습
16
How deadlock can be avoided
Deadlock Modeling (2) (o) (p) (q) How deadlock can be avoided ITEC502 컴퓨터 시스템 및 실습
17
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 컴퓨터 시스템 및 실습
18
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 컴퓨터 시스템 및 실습
19
Deadlock Detection Allow system to enter deadlock state
Detection algorithm Recovery scheme ITEC502 컴퓨터 시스템 및 실습
20
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 컴퓨터 시스템 및 실습
21
Detection with One Resource of Each Type (2)
Data structures needed by deadlock detection algorithm ITEC502 컴퓨터 시스템 및 실습
22
Detection with One Resource of Each Type (3)
An example for the deadlock detection algorithm ITEC502 컴퓨터 시스템 및 실습
23
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 컴퓨터 시스템 및 실습
24
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 컴퓨터 시스템 및 실습
25
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 컴퓨터 시스템 및 실습
26
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 컴퓨터 시스템 및 실습
27
Review Resource Introduction to deadlocks Deadlock modeling
The ostrich algorithm Deadlock detection and recovery ITEC502 컴퓨터 시스템 및 실습
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.