edited by
22,664 views
61 votes
61 votes

A shared variable $x$, initialized to zero, is operated on by four concurrent processes $W, X, Y, Z$ as follows. Each of the processes $W$ and $X$ reads $x$ from memory, increments by one, stores it to memory, and then terminates. Each of the processes $Y$ and $Z$ reads $x$ from memory, decrements by two, stores it to memory, and then terminates. Each process before reading $x$ invokes the $P$ operation (i.e., wait) on a counting semaphore $S$ and invokes the $V$ operation (i.e., signal) on the semaphore $S$ after storing $x$ to memory. Semaphore $S$ is initialized to two. What is the maximum possible value of $x$ after all processes complete execution?

  1. $–2$
  2. $–1$
  3. $1$
  4. $2$
edited by

9 Answers

–4 votes
–4 votes
p(S)

Read x;

store x;

v(s) so max possible value -2 by execution of any possiblity of sequence w x=1,X x=2,Y x=0,Z x=-2 or w x=1,Y x=-1,X x=0,Z x=-2 or any other squence .
Answer:

Related questions