- Process X executes the P operation on semaphores a,b and c;
- Process Y executes the P operation on semaphores b,c and d;
- Process Z executes the P operation on semaphores c,d and a.
After completing the execution of its code segment, each process invokes the V operation (i.e, signal) on its three semaphores. All semaphores are binary semaphores initialized to one. How do I recognise a deadlock-free order of invoking the P operations by the processes ? For illustration, the given examples are the following
- X: P(a)P(b)P(c) Y:P(b)P(c)P(d) Z:P(c)P(d)P(a)
- X: P(b)P(a)P(c) Y:P(b)P(c)P(d) Z:P(a)P(c)P(d)
- X: P(b)P(a)P(c) Y:P(c)P(b)P(d) Z:P(a)P(c)P(d)
- X: P(a)P(b)P(c) Y:P(c)P(b)P(d) Z:P(c)P(d)P(a)
Asked By : Đēēpak Shãrmã
Answered By : M’vy
A (non-strict) partial order is a binary relation “≤” over a set P which is reflexive, antisymmetric, and transitive, i.e., which satisfies for all a, b, and c in P:
- a ≤ a (reflexivity);
- if a ≤ b and b ≤ a then a = b (antisymmetry);
- if a ≤ b and b ≤ c then a ≤ c (transitivity).
For the processes, there is no interest in the first two clauses, resources are distinct and unique. All we care about is the transitivity. Assuming a given order of resources, we then must ensure that each process never claims a lower resource before a higher one. Building a deadlock free order is as simple as ordering the resources. This choice is arbitrary. To solve your examples, we need to find what order has been chosen, if one exists, and verify it is a poset.
- is not a poset since $a > c$ (from X) and $c > a$ (from Z) contradicts the transitivity.
- is a poset since $b > a > c > d$ in all groups.
- is not a poset since $b > c$ (from X) and $c > b$ (from Y) contradicts the transitivity.
- is not a poset since $a > c$ (from X) and $c > a$ (from Y) contradicts the transitivity.
Conclusion, only 2 is a deadlock free order as the circular wait condition is removed.
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/21665 Ask a Question Download Related Notes/Documents