in Operating System
356 views
0 votes
0 votes

Consider the concurrent program:

x:=1;

cobegin

x:= x + x + 1|| x:= x + 2

coend;

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

 

The above question is from madeeasy test series.

Solution:

1. x=1, run x = x + 2 then x = x + x + 1 finally x will be 7 

2. x=1, run x = x + 2 then x = x + x + 1 parallely then x will be 3

3.  x=1, run x = x + x + 1 then  x = x + 2 finally x = 5

Possible values of x would be 3, 5, 7 and Sum = 15

 

My Doubt:

Wont there be 1 more case where we run x = x + x + 1 but load only value of highlighted x i.e it becomes x = 1 + x + 1

and after it we will run x = x + 2 i.e x = 1 + 2 = 3

now again running x = 1+ x + 1  and now substituting the value of x as 3

x = 1 + 3 + 1 = 5

in Operating System
356 views

2 Comments

in question telling all possible value  of the x means value of x should be different

hence here only three value of x is different  which is 5,3,7
0
0
I got your point but is my possibility asked in the doubt valid?
0
0

Please log in or register to answer this question.