Consider two processes $P_1$ and $P_2$ accessing the shared variables $X$ and $Y$ protected by two binary semaphores $S_X$ and $S_Y$ respectively, both initialized to 1. $P$ and $V$ denote the usual semaphore operators, where $P$ decrements the semaphore value, and $V$ increments the semaphore value. The pseudo-code of $P_1$ and $P_2$ is as follows: $$\begin{array}{|l|l|}\hline \text{$P_1$:} & \text{$P_2$:} \\\hline \text{While true do \{} & \text{While true do \{} \\ L_1:\ldots\ldots & L_3:\ldots\ldots \\ L_2:\ldots\ldots & L_4:\ldots\ldots \\ \text{X = X + 1;} & \text{Y = Y + 1;} \\ Y=Y-1;&X = Y-1; \\ \text{$V(S_X);$} & \text{$V(S_Y);$} \\ \text{$V(S_Y);$} & \text{$V(S_X);$} \\\}&\} \\\hline \end{array}$$ In order to avoid deadlock, the correct operators at $L_1$, $L_2$, $L_3$ and $L_4$ are respectively.
$P(S_Y), P(S_X); P(S_X), P(S_Y)$
$P(S_X), P(S_Y); P(S_Y), P(S_X)$
$P(S_X), P(S_X); P(S_Y), P(S_Y)$
$P(S_X), P(S_Y); P(S_X), P(S_Y)$
hey in option c) l1 p(sx) l2 p(sx) (in p1) and l3 p(sy) ,l4 p(sy) (in process p2) rt
so how P1:P(X) | P2:P(x) (blocked) | P1:P(Y) | P2:P(Y)(blocked) this will be done ??
you did for option d)
see this
Option (A):
$\Rightarrow$ Deadlock possible
Option (B) . Same as Option (A). Deadlock possible.
Option (C):
No need to think of another process to get a deadlock situation:
$\Rightarrow$ Both processes will be blocked once they start.
Option (D) is ok ! as far as deadlock is concerned.
@ mcjoshi ..yes...I think the same ...but I asked @wanted...to his comment
@debashidh
in option A there may b not deadlock .