Consider the example code below,
int msg = 0;
msg = 1; r = msg;
Is it OK to write such code? Is there anypossibility that P2 read some "intermediate" value (i.e. neither 0 nor 1)?
I have researched on this topic for a while. However,I am still not sure if we are allowed to write the above code.
Some said we should use mutex.
Some saidthat a native-wordstore is atomic.
Some said a alignednative-wordstore is atomic.
Which one is right? Can programmers just write the above code, then assume that a native-word / aligned native-word store is atomic?
Any comment will be appreciated.