try this code block in one thread
int a = 0;
a = 1; //the thread is running on cpu A
a? //the thread is switched and running on cpu B
so a can be 0 ?
No, a must be 1 because there is a happens-before relationship between the assignment a = 1 and the value of a being read later by the same thread.
If x and y are actions of the same thread and x comes before y in program order, then hb(x, y).
a is written back to heap, or its value is stored in the process control block. See also stackoverflow.com/questions/30774550/…a is a local variable. That means each thread has a copy of its own of a.
ashared? How is it updated and by what threads? Without proper notation this is highly bad question