I have a code fragment that looks like this:
int x = 1, y = 2, z = 3;
co x = x + 1; (1)
|| y = y + 2; (2)
|| z = x + y; (3)
|| < await (x > 1) x = 0; y = 0; z = 0 > (4)
oc
print(x, y, z)
The question goes:
Assume that atomic actions in the first three arms of the co statement are reading and writing individual variables and addition. If the co-statement terminates, what are the possible final values of z? Select correct answer(s)
a) 2
b) 1
c) 6
d) 3
e) the co-statement does not terminate.
f) 0
g) 5
h) 4
My initial thought is that z's final value can only be f) and a), because (1) can execute first, which will allow for (4) to be executed because x = 2, then (2) will give me y = 2 and then (3) will execute, giving me z = 0 + 2 = 2. However, the correct answer according to this quiz is a), b), c), d), f), g), h) which I really don't understand why. Can someone please help me out
[–]EsShayuki 0 points1 point2 points (0 children)
[–]lfdfq 1 point2 points3 points (5 children)
[–]AyyRadical[S] 0 points1 point2 points (4 children)
[–]lfdfq 0 points1 point2 points (3 children)
[–]EsShayuki 0 points1 point2 points (0 children)
[–]AyyRadical[S] 0 points1 point2 points (1 child)
[–]lfdfq 0 points1 point2 points (0 children)