Preview Deadlock Condition Resource Allocation Graph Resource

Transcription

Preview Deadlock Condition Resource Allocation Graph Resource
3/31/2015
Preview
Deadlock Condition
Deadlock Condition
 Resource Allocation Graph
 Four strategies for Dealing Deadlock
 Deadlock Detection and Recovery
A deadlock situation can arise if and only if
the following four conditions hold
simultaneously in a system.
1. Mutual exclusion
2. Hold and wait
3. No preemption
4. Circular wait


Detection with one resource of each type
Detection with Multiple resource of each type

Recovery from Deadlock


Deadlock Detection Algorithm
COSC450 Operating System Spring 2015
Dr. Sang-Eon Park
1
Resource Allocation Graph






COSC450 Operating System Spring 2015
Dr. Sang-Eon Park
2
Resource-Allocation Graph
This graph consists of a set of vertices V and a
set of edges E.
The set of vertices V is partitioned into two types
P = {P1, P2, …, Pn}= set of processes and
R = {R1, R2, …, Rm} = set of resources
Edge from a process to a resource P → R denote
process P request resource R and currently
waiting
Edge from a resource to a process R → P denote
resource R is currently held by process P
COSC450 Operating System Spring 2015
Dr. Sang-Eon Park
3
Deadlock Example
COSC450 Operating System Spring 2015
Dr. Sang-Eon Park
COSC450 Operating System Spring 2015
Dr. Sang-Eon Park
4
Deadlock Example
5
COSC450 Operating System Spring 2015
Dr. Sang-Eon Park
6
1
3/31/2015
Four Strategies for Dealing Deadlock
Deadlock Detection and Recovery
Just ignore
 Detection and Recover
 Dynamic Avoidance by careful allocation
 Prevention – by negating one of the four
conditions necessary to cause deadlock

A system let a deadlock occur.
 The system keeps tracking whether there
is any deadlock or not.
 When a deadlock situation is detected by
system, system takes some action to
recover from the deadlock.

COSC450 Operating System Spring 2015
Dr. Sang-Eon Park
7
COSC450 Operating System Spring 2015
Dr. Sang-Eon Park
Deadlock Detection and Recovery
Deadlock Detection and Recovery
(Detection with one resource of each type)
(Detection with one resource of each type)
8
Deadlock Detection with one resource of
each type
 A simple graph algorithm which detect a
cycle in a directed graph can detect a
deadlock

COSC450 Operating System Spring 2015
Dr. Sang-Eon Park
9
COSC450 Operating System Spring 2015
Dr. Sang-Eon Park
Deadlock Detection and Recovery
Deadlock Detection and Recovery
(Detection with Multiple resource of each type)
(Detection with Multiple resource of each type)
10
We need matrixes for deadlock detection algorithm.




Existing resource matrix – Present how many numbers of
resources per each type
Available resource matrix – Present how may number of
resources per each type are available at any moment, since
some of resources are assigned to processes are not
available
Current allocation matrix – present how resources are
currently held by processes
Request matrix – present how many resources are needed
for processes to finish their job.
We can observe following equations from the four matrix structure.
n
C
i 1
COSC450 Operating System Spring 2015
Dr. Sang-Eon Park
11
i, j
 Aj  E j
COSC450 Operating System Spring 2015
Dr. Sang-Eon Park
12
2
3/31/2015
Deadlock Detection and Recovery
Deadlock Detection and Recovery
(Detection with Multiple resource of each type)
(Detection with Multiple resource of each type)
The deadlock detection algorithm is based on
comparing vectors.
 Let’s define the relation A ≤ B between two
vector A and B means that each element of A is
less than equal to corresponding element of B.
Ex)
A = (1, 2, 0 2), B = (1, 3, 0 2): A ≤ B is true? Yes
A = (1, 2, 0, 2), B = (2, 0, 0, 0): A ≤ B is true? No
A Deadlock detection algorithm

COSC450 Operating System Spring 2015
Dr. Sang-Eon Park
1.
2.
3.
4.
All process start with unmarked
Look for an unmarked process Pi, for which the
ith row of R is less than or equal to A
If such a process is found, add the ith row of C to
A, mark the process and go back to step 1
If no such a process exists, the algorithm
terminate
13
COSC450 Operating System Spring 2015
Dr. Sang-Eon Park
Deadlock Detection and Recovery
Deadlock Detection and Recovery
(Detection with Multiple resource of each type)
(Detection with Multiple resource of each type)
Ex)
E = (4, 2, 3, 1)
A = (2, 1, 0, 0)
Ex)
E = (7, 2, 6)
A = (0, 0, 0)
Ex)
E = (4, 2, 3, 1)
A = (2, 1, 0, 0)
0010
2001
C  2001, R  1010 
0120
2100
- No deadlock
0010
2001
C  2001, R  2111
0120
2100
- Deadlock
COSC450 Operating System Spring 2015
Dr. Sang-Eon Park
15
Deadlock Detection and Recovery
COSC450 Operating System Spring 2015
Dr. Sang-Eon Park

16
Recovery through preemption

010 
000 
200
202




C  303 , R  001 




211
100 
002 
002 
COSC450 Operating System Spring 2015
Dr. Sang-Eon Park
010 
000 
200
202




C  303 , R  000 




211
100 
002 
002 
Recovery from Deadlock
(Detection with Multiple resource of each type)
Ex)
E = (7, 2, 6)
A = (0, 0, 0)
14


Recovery through rollback



17
take a resource from some other process
depends on nature of the resource
checkpoint a process periodically
use this saved state
restart the process if it is found deadlocked
COSC450 Operating System Spring 2015
Dr. Sang-Eon Park
18
3
3/31/2015
Recovery from Deadlock

Recovery through killing processes




Crudest but simplest way to break a deadlock
Kill one of the processes in the deadlock cycle
The other processes get its resources
The killed process need to start from the
beginning
COSC450 Operating System Spring 2015
Dr. Sang-Eon Park
19
4

Similar documents