in Operating System edited by
2,105 views
22 votes
22 votes

Consider the concurrent program 

x := 1; 
cobegin 
    x := x + x + 1 || x := x + 2 
coend;

Reading and writing of a variable is atomic, but evaluation of an expression is not atomic. The set of possible values of variable $x$ at the end of execution of the program is

  1. $\left\{3\right\}$
  2. $\left\{7\right\}$
  3. $\left\{3, 5, 7\right\}$
  4. $\left\{3, 7\right\}$
  5. $\left\{3, 5\right\}$
in Operating System edited by
2.1k views

1 comment

0
0

1 Answer

18 votes
18 votes
Best answer
$1. x = 1$, Run $x = x + 2$ then $x= x + x + 1$ finally $x$ will be $7$.
$2. x = 1$,  run $x = x + 2$ and $x = x + x + 1$, parallely ..
$x = 5 , 3$
Final answer would be $\{3, 5, 7\}$
edited by

4 Comments

nice explanation @Bikaram sir u remove all the doubts
0
0
Bikram Sir's comment should become the answer.
0
0

Since it is given that the evaluation of an expression is not atomic, can 4 be an answer as well? (Although not mentioned in options)

While evaluating the first expression x = x+x+1, if after evaluation of x=x+x, resulting in value of x equal to 2, can the process preempt to the other condition , i.e x= x+2, to give the value 4? 

0
0
Answer:

Related questions