6,524 views
2 votes
2 votes
If I have 10 processes and each process wants 3 resources so now usually we first calculate the maximum no of resources so that there is deadlock by assigning one resource less than the maximum need of the resource and then add 1 to it , to find the minimum no of resources to remove deadlock ,I agree to that logic too so by using that I get the answer as 21 ,Now what if I assign 1 resource initially to 9 processes and then assign 3 resource to 10th process or assign 2 resource to any one of the process and 1 resource to the remaining this would account to 11 which will lead to deadlock and then add 1 to it =12 ,this would remove deadlock , what is the mistake in this logic ?

3 Answers

7 votes
7 votes

Total number of just enough free resources needed in a system such that Deadlock never happens is given by :

where $n$ is the total number of processes in the system.

So, if there are $21$ resources in our system then it is just the enough number that deadlock can never happen, no matter how the distribution of resources among processes takes place.

Mistake in your logic is that you are Not considering that there is a chance of free resources(which in your case =12) getting uniformly distributed among the requesting processes, which is sufficient to bring the Deadlock.

1 votes
1 votes

You are considering one of the best cases in which you are completing the need of 10 th process,consider this   after assigning 1 resource to each of 9 processes,  still these 9 processes needs 2 resources more for execution so they are still requesting to os.. And 10 th one is requesting 3 Resources. Now any free resources can be given to any of these 10 processes. So it may happen that i give 11 more resources and they are assigned in such a way that  each process now has 2 resources and now system is in deadlock.

So even with 20 resources, there is possibility of deadlock so we need at least 21.In short we consider a worst case synario. We want to ensure that every case is deadlock free. 

1 votes
1 votes
condition for deadlock is /

process * ( mx need -1) = RESOURCES.

now if u have to remove deadlock then either u increase the resource by one or decrease the process by one.

so here it will be  2*10=20 . at which deadlock occur. ( 21 ).

NOTE: this 21 will always lead the system in safe state.

Not every unsafe state is a deadlock . but we avoid unsafe state that's why 21 is answer but your logic take the system in unsafe state but further it can be a deadlock. now 10 finished execution. there are three resources available which are given to one each . now everyone is again in deadlock. so in unsafe state there may or may not be deadlock. it depends on in which order execution takes place

Related questions

1 votes
1 votes
2 answers
1
radha gogia asked Oct 14, 2015
539 views
Just wanted to know that if none of the needs of a process is met so can we directly say that it is unsafe state as well as will lead to deadlock since none of the needs ...
5 votes
5 votes
4 answers
2
Prateek Dwivedi asked Jun 27, 2015
31,831 views
This is a question from Operating System concepts by Silberschatz, Gagne and Galvin. On very first go I could make that in such a situation deadlock can never occur. But ...