Question: Consider the following program: P 1 : { shared int x; x = 1 0 ; while ( 1 ) { x = x -

Consider the following program:
P1: {
shared int x;
x =10;
while (1){
x= x -1;
x= x +1;
if (x !=10)
printf("x is %d", x)
}
}
}
P2: {
shared int x;
x =10;
while (1){
x= x -1;
x= x +1;
if (x!=10)
printf("x is %d", x)
}
}
}
For each of the following outputs, if it is possible to have that output, show an interleaving of statements that would result in the output.
x is 10 is printed.
X is 8 is printed.
You should remember that the increment/decrements at the source language level are not done atomically, that is, the assembly language code:
LD RO, X /* load RO from memory location x */
INCR RO /* increment RO */
STO RO, X /* store the incremented value back in X */
implements the single C increment instruction.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!