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:
$P_1$: |
$P_2$: |
While true do {
$L_1$:……..
$L_2$:……..
X = X + 1;
Y = Y -1;
$V(S_X);$
$V(S_Y);$ } |
While true do {
$L_3$:……..
$L_4$:……..
Y = Y + 1;
X = Y -1;
$V(S_Y);$
$V(S_X);$ |
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)$