Handling Deadlocks: Avoidance

Consider the following state with 3 processes and 12 disks. We avoid deadlock by following the steps below the table:

Process Maximum Needed: Currently Allocated: Available:
P0
10
5
3
P1
4
2
P2
9
2
  1. Process P1 needs to access a total of 4 disks, 2 of which it already accesses. Since there are 3 available disks, we can safely let P1 access 2 more disks. After P1 finishes accessing all 4 disks, there will be 2 + 2 + 1 = 5 available disks.
  2. Next, notice that process P0 needs to access a total of 10 disks, 5 of which it already accesses. Since there are now 5 available disks, we can safely let P0 access these 5 available disks. After P0 finishes accessing all 10 disks, there will be 10 available disks.
  3. Finally, process P2 needs to access a total of 9 disks, 2 of which it already accesses. Since there are now 10 available disks, we can safely let P2 access 7 of the available disks. After P2 finishes accessing all 9 disks, there will be 12 available disks, so we avoid deadlocks!