I have a question about resource alocation to avoid dead lock

In the code below, three processes are competing for six resources labeled A to F.How can I modify the get request in each procedure in this graph to avoid dead lock You cannot move requests across procedures, only change the order
inside each procedure.

• You should edit your answer to show us what you think about this problem, and how you tried to resolve it. – user80502 Jun 3 '18 at 10:42
• Take the proof of correctness as an exercise. – Sumeet Jun 6 '18 at 8:46

1 Answer

The main resources to be focused here are the common ones : $B$ , $C$ and $D$. To prevent deadlock from ever occurring you should focus on breaking $circular wait$, which is one of the 4 necessary conditions for deadlock.

For that lets make the common resources request as early as possible: Consider this:

$P_{o}()$ $\ $$\$$\ $$\$$\ $$\$$\$ $P_{1}()$ $\ $$\$$\ $$\$$\ $$\$$\$ $P_{2}()$

$get(B)$ $\ $$\$$\ $$\ get(B) \$$\ $$\$$\$ $get(C)$

$get(C)$ $\ $$\$$\ $$\ get(D) \$$\ $$\$$\$ $get(D)$

$get(A)$ $\ $$\$$\ $$\ get(E) \$$\ $$\$$\$ $get(F)$

The proof that the above sequence never leads to deadlock is easy and can be got by considering the different orders in which common resources are acquired.