in Operating System
5,871 views
8 votes
8 votes
Why unsafe state not leads to deadlock?

Please don't redirect to any other link. Explain it by taking an example.
in Operating System
5.9k views

2 Comments

when system is in unsafe state there is possibility of deadlock, but it doesnot mean that deadlock will never occur, there are some cases when system is in unsafe state and end up in deadlock.
0
0
Please mention those cases.
0
0

1 Answer

9 votes
9 votes
Best answer
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.

selected by

2 Comments

@stblue it means that

Case 1: Unsafe state not lead to deadlock

Currently p1 realize that it dont need printer so it will releas printer, but before p1 release the system is in unsafe state but not in deadlock and after relasing printer the system turns out to be in safe state.

In this if p1 not ready to release Printer (and also not making further request) then system will be in unsafe state only for ever but not deadlock. 

Right??

0
0
Ya correct, system will be in unsafe state but not in deadlock.
There are other reasonsas well by which system comes out of unsafe state without entering into deadlock, suppose due to some reason some running process get killed, all the resource it was holding get free, and this extra free  resources, might become the reason for system to get out of unsafe state. So we can't always guarantee that system will goes to deadlock if it is in unsafe state.
1
1

Related questions