In one thread I have
write a = 0
write a = 1
write volatile flag = 1
In 2nd thread I have
read volatile flag // This always happens after I write volatile flag in thread 1
read a
Can a reordering happen so I see read a
returning 0 in the 2nd thread?
If not, could someone, please, explain in detail why?
I'm asking becuase I'm puzzled by this definition from the JLS:
Among all the inter-thread actions performed by each thread t, the program order of t is a total order that reflects the order in which these actions would be performed according to the intra-thread semantics of t.
It looks as if allows for reordering in this situation?