333 views
1 votes
1 votes

1 Answer

2 votes
2 votes

$S_1$ and $S_3$ are false

Semaphore A is there to ensure that there is consistency in the value of $rc$. As multiple processes will be sharing this variable, any modification on $rc$ is a critical section. Going with the modification from statements $S_1$ and $S_3$, it is important to understand that they are there to ensure that no two processes modify the value of $rc$ simultaneously. If we remove line(1) - line(4) or line(6)-line(8) or both, there is a possibility that two or more processes to execute line(2) or line(7) simultaneously and thus lead to an inconsistent value of $rc$.

$S_2$ is false

Let us consider the following course of concurrent execution of a reader process $P_r$ and writer process $P_w$

  1. $P_r$ starts execution and gets preempted immediately after executing line(4). Here it is worth noting that semaphore A has a value 1 and semaphore C has a value of 0 because of execution of line(3).
  2. As soon as the reader process $P_r$ is preempted, writer process $P_w$ goes into running state. As per the modifications of $S_2$, it will try to execute Wait(A) initially and the value of the semaphore A is changed to 0. As the $P_w$ proceeds, it gets blocked because of Wait(C) on next line, as the process $P_r$ has already set that to 0.
  3. Now let the reader process $P_r$ proceeds it's execution and perform it's reading operation and complete it. Later while reducing the count of readers performing read operation it get's blocked because of Wait(A) on line(6) as the value of semaphore A is set to 0 by process $P_w$.
  4. At this point, the two processes are blocked (waiting for other to release respective semaphores) and thus the system is in a deadlock state.

Thus $S_2$ is also false.

HTH

edited by

Related questions