1,733 views
5 votes
5 votes

Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S, T and U:

Process P:                             Process Q:
P(S)                                        W:
P(T)                                        X:
P(U)                                        Y:
Print ‘a’                                  Print ‘a’;
Print ‘b’                                  Print ‘b’;
V(S)                                        A:
V(T)                                        B:
V(U)                                        C:

Q1: What should be written at W to avoid deadlock?
(a) P(T)                                     (b) P(U)
(c) P(S)                                     (d) Not possible to avoid deadlock


Q2: What should be written at X and Y for the above problem?
(a) P(S), P(T)                              (b) P(T), P(U)
(c) P(S), P(U)                              (d) None

3 Answers

Best answer
12 votes
12 votes

$S,T$ and $U$ are binary semaphores shared between two concurrent processes $P$ and $Q$. So, $S,T$ and $U$ can have $0$ or $1$ as their value. If they take $0$ as their initial value then, $P$ cannot execute (because it performs down on all $3$ semaphores), In this case for Process $Q$ to execute $W,X$ and $Y$ have to be UP operations in some order. ( but it's not the case as all options are down operations). So, it means to answer this question Initially $S = 1,T = 1$ and $U = 1$.

Process $P$ performs DOWN on $S,T,U$ in order. So if at the same time $Q$ performs DOWN on these binary semaphores in some orders (remember $3*2*1 = 6$ ways), Some of these $6$ ways may result in Deadlock.

In process $P$ , Down on $S$ is performed. So if $W$ is $P(T)$ or $P(U)$, i.e, down on $T$ or $U$ by Process $Q$ Deadlock happens. ( This eliminates $4$ ways) And Confirms that $W$ has to be $P(S)$. Answer (C) for $Q_{1}$

And out of remaining $2-ways$ one is $\color{red}{W,X,Y = P(S),P(T), P(U)}$ which is sure shot answer for $Q_{2}$ And, it's pretty interesting to trace it out that remaining case $\color{green}{W,X,Y = P(S),P(U),P(T)}$ is also deadlock free.

selected by
3 votes
3 votes

1. with only W it is "Not possible to avoid deadlock". but yes W = P(S) , X = P(T),  Y = P(U)  results deadlock free system.
So W = P(S)

2. if W = P(S) then X = P(T),  Y = P(U) works fine.

0 votes
0 votes
Q1 . at W if we use P(T) or P(U) then there is possibility of deadlock

     w = P(S)

Q2. P(T), P(U)

  if w = P(S)  then P(U) , P(T) also accepted

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
0 answers
2
amitqy asked Nov 21, 2018
948 views