Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Operating Systems
Deadlocks:
Avoidance Detection - Recovery
Summer 2011
Cornell University
Today
Safe state
Deadlock avoidance
Banker's Algorithm
Deadlock detection
Deadlock recovery
Deadlock Avoidance
Safe State
the resources that Pi can still request can be satisfied by the currently
available resources plus the resources held by all Pj, where j < i.
Safe State
Max Needs
Current Needs
p0
10
p1
p2
3 drives remain
R1
P1
P2
R1
P1
P2
R2
6
Banker's Algorithm
Banker's Algorithm
n: integer
# of processes
m: integer
# of resources
available[1..m]
max[1..n,1..m]
allocation[1..n,1..m]
need[1..n,1..m]
Banker's Algorithm
Banker's Algorithm
Safety Algorithm
work[1..m] = available
Step 1:
Find an i such that finish[i]=false and need[i] <= work
now */
/* were done */
Step 2: Found an i:
finish [i] = true
/* assume this process were to finish, and its allocation back to the
go to step 1
Step 3: If finish[i] = true for all i, the system is safe. Else Not
10
Allocation
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
Max
A B C
7 5 3
3 2 2
9 0 2
2 2 2
4 3 3
Available
A B C
3 3 2
This is a safe state: safe sequence <P1, P3, P4, P2, P0>
11
Allocation
A B C
0 1 0
3 0 2
3 0 2
2 1 1
0 0 2
Max
A B C
7 5 3
3 2 2
9 0 2
2 2 2
4 3 3
Available
A B C
2 3 0
This is still safe: safe seq <P1, P3, P4, P0, P2>
Allocation
A B C
0 3 0
3 0 2
3 0 2
2 1 1
0 0 2
Max
A B C
7 5 3
3 2 2
9 0 2
2 2 2
4 3 3
Available
A B C
2 1 0
13
Bankers algorithm.
14
Deadlock Detection
15
Collapse resources
16
Detection Algorithm
n: integer
# of processes
m: integer
# of resources
available[1..m]
request[1..n,1..m]
allocation[1..n,1..m]
finish[1..n]
Detection Algorithm
work[]=available[]
finish[i]=false;
request[i]<=work
if no such i exists, go to 5.
work=work+allocation[i]
finish[i] = true, go to 3
18
Allocation
A B C
0 1 0
2 0 0
3 0 3
2 1 1
0 0 2
Request
A B C
0 0 0
2 0 2
0 0 0
1 0 0
0 0 2
Available
A B C
0 0 0
19
Deadlock Recovery
20
Today
Safe state
Deadlock avoidance
Banker's Algorithm
Deadlock detection
Deadlock recovery
21