362 views
1 votes
1 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

Please log in or register to answer this question.

Related questions

1 votes
1 votes
2 answers
1
Ankit Sahu asked Feb 4, 2019
1,142 views
Why the value of D is 80 in concurrent process question and not 0? The question didn't mention that each statement take 3 instruction to execute so why assume that?
2 votes
2 votes
1 answer
3
joleyasarthak asked Nov 21, 2022
950 views
Please help with the minimum value. Problem is from the gate wallah study handout.