791 views

Consider two processes P1 and P2, each needed 3 resources 1, 2 and 3 in a database. If each processes ask them in any order, then the number of ways possible in which system is guaranteed to be deadlock-free ________.

Similar to https://gateoverflow.in/220031/deadlock. It seems many answers are possible and no proper explanation is present.

Please check the above link for more solutions. I am attaching below the made easy solution. Please explain a proper procedure to solve this.

For each combination of resource request, you have to consider cases where deadlock may arise.

Say, P1 requests: R1, R2, R3 and P2 requests R1, R3, R2

P1 gets preempted while using R2, P2 starts after that and gets preempted while using R3. Now P1 resumes and requires R3 which is present with P2. and P2 requires R2 which is present with P1. Hence, both processes are unable to execute further.

There are different combinations of requests where deadlock can arise. Just take one pair at a time and interchange their order.

This is how you should approach this.

Also, I am not good with PnC. So, kindly explain how to solve further.

@Shaijal Tripathi, You are absolutely correct. This is the approach for this question.  Total $6!$ ways are possible, among which $180$ will be deadlock free.

Say, P1 requests: R1, R2, R3 and P2 requests R1, R3, R2

p1 acess R1 then prempted then p2 start and will wait for R1,now p1 can finish its execution for any order of remaining 2 resources because both are available ,it means  order with this will be deadlock free,why this order is discarded?

according to me all order(arrangement) in which first resource request by p1 and p2 is same will be deadlock free ,because after aceesing first resouce by any one process if  prempted,other process will wait without holding any resouce,it means first process that wasprepted can continue its execution without deadlock.

in this way no of order come will be 120*2=240;please explain?