deadlock avoidance
Example of Banker’s Algorithm
- 5 processes P0 through P4; 3 resource types A (10 instances),
- B (5instances, and C (7 instances).
- Snapshot at time T0:
|
Allocation |
Max |
Available |
P0 |
0 1 0 |
7 5 3 |
3 3 2 |
P1 |
2 0 0 |
3 2 2 |
|
P2 |
3 0 2 |
9 0 2 |
|
P3 |
2 1 1 |
2 2 2 |
|
P4 |
0 0 2 |
4 3 3 |
|
- The content of the matrix. Need is defined to be Max – Allocation.
Need
P0 |
A B C |
P1 |
1 2 2 |
P2 |
6 0 0 |
P3 |
0 1 1 |
P4 |
4 3 1 |
The system is in a safe state since the sequence < P1, P3, P4,P2, P0> satisfies safety criteria.
Example P1 Request (1,0,2)
- Check that Request Available (that is, (1,0,2) (3,3,2) true.
|
Allocation |
Need |
Available
|
P0 |
0 1 0 |
7 4 3 |
2 3 0 |
P1 |
3 0 2 |
0 2 0 |
|
P2 |
3 0 1 |
6 0 0 |
|
P3 |
2 1 1 |
0 1 1 |
|
P4 |
0 0 2 |
4 3 1 |
|
- Executing safety algorithm shows that sequence <P1, P3,
P4, P0, P2> satisfies safety requirement.
- Can request for (3,3,0) by P4 be granted?
- Can request for (0,2,0) by P0 be granted?