I have these 2 functions, executed in parallel :
int x = 10 // a common variable
void P1(){ void P2(){
while(1){ while(1){
x--; x--;
x++; x++;
if(x!=10) if(x!=10)
printf("x=%d",x); printf("x=%d",x);
} }
} }
parbegin P1(); P2();
parend
The functions occasionally output x=8, which does not look possible.
Does it have to do with the fact that the x-- and x++ operations are actually translated into 3 instructions in machine-code ( see the symbolic assembly decode )?
LD R0, X // LOAD into R0 the value of x
INCR R0 (or DECR R0) // { INCR | DECR }-increase/decrease the value of R0 by 1
STO R0, X // STORE the new value back to x
If yes,
then what is the order of the instructions, so that the output "x=8" was generated?
If not,
then why does it occasionally print x=8?
