94.5k views
1 vote
Suppose that three different processes, P1, P2, and P3, share the variables x and y and execute the following code fragments concurrently, and that the initial value of y is 8. The instructions to add and subtract in memory are not atomic.

P1: P2: P3:
x = y; x = y; x = y;
x = x + 1; x = x - 1; x = x - 1;
y = x; y = x; y = x;

Which of the following values of y are possible after all three processes finish executing their code fragments?

a. 5
b. 6
c. 7
d. 8
e. 9
f. 10

User Abdeen
by
3.6k points

1 Answer

2 votes

Answer:

c. 7

Step-by-step explanation:

The initial value of the y is 8. When the instructions are inserted in the memory the coding will change its value and the new value for the y will be different from the initial value. The different is due to the instruction in the memory which are not atomic and the process finishes the execution of the command. The new value will be y - 1 which means 8 -1 = 7.

User Ruty
by
3.8k points