Process |
Allocated |
Required |
Available |
|
A |
Printer |
A |
Printer |
A |
Printer |
P1 |
2 |
2 |
2 |
0 |
1 |
0 |
P2 |
1 |
0 |
1 |
2 |
Suppose this is the Current scenario, Here currently no safe sequence exist i.e system is in unsafe state. Here A and Printer are two independent task.
Case 1: Unsafe state not lead to deadlock
Suppose after 30 sec P1 realize he doesn't need printer, so he release all the resources he holds for printer, so now available resources is (1, 2). Now we can fulfill resource request for process P2, and wait for P2 to complete its execution. When P2 completes its execution, it freed up all the resources. So available resources now is (2,2). Now we Can fulfill the demand of P1 as well.
So we end up getting a safe sequence i.e P2 P1. This happens because P1 release some of its resources.
Case 2: Unsafe State lead to deadlock
Suppose Process P1 request for resource, Now Available resource is (0,0). P1 still need (1,0) and P2 still need (1,2). So in this case even if P1 release some resources, we can't save ourself from deadlock.
So, in general, we can say Unsafe state may lead to deadlock, but this is not always the case.