Microsoft Interview Question
Developer Program EngineersWhy its n*k-n+1 could the people commented explain, please.
I think its "None of the above".
* If there is only one resource there is no question of deadlock.
* If there are k instances of the resource and each instance need to be locked to access it then it is equivalent to having more than one resource.
* If there are more than one resource that each needs locking then, I don't think its number of resources or its need-to-be-locked instances dictates the deadlock scenario. The program should avoid the deadlock. For e.g. There are 2 processes and 2 resources process 1 locked resource 1 and waiting for resource 2, while process 2 has locked resource 2 and waiting for resource 1. How does the number of instances or resources avoid the deadlock scenario?
@kannan its like n*k-n resources are required so that each process can have one less than the resource instance they require.. but still deadlock can occur as each process depend upon other process for one resource instance ..if we provide n*k-n+1 resource instances than the deadlock condition will never occur.
Thanks for the explanation.
So I guess there will be resource manager who will figure out which resources are already acquired and when a process asks for a resource it grants access to a non-acquired resource if possible.
this is not correct take this example there 2 processes and 2 resource types R1 & R2 each process requires 10 of each type. now according tho answer above 19 resources of each type are sufficient to avoid dead lock but it's incorrect dead lock can occur if p1 acquires 10 R1 and 9 R2 and p2 acquires 9 R1 & 10 R2 there is a dead lock.so above answer is wrong plz some one give me correct answer i opted n*k in my exam i couldn't any other option better than this.
Shouldn't ordering the resources fix the deadlock?
All processes lock the resources in one order that all of them agree upon.
Hence we require only k resources.
Comments/suggestions welcome!
Correct Answer is : N*K - (N - 1) [or] (Total Number Process * Total Number of Resource ) - (Total Process -1 )
Let me prove my formulae
For Ex: There are 3 process and each require 2 resources to complete the task. So the Minimum number of resource which guarantee the dead lock free is 4.(Source : Tata McGraw Hill Book)
Formula: 3*2 - (3-1) = 6-2 = 4
For Ex: There are 5 process and each require 2 resources to complete the task. So the Minimum number of resource which guarantee the dead lock free is 6.(Source : Again Tata McGraw Hill Book)
Formula: 5*2 - (5-1) = 10-4 = 6
Hence the proof..!
I think it would be n*k-n+1....
- import_neo November 06, 2010