Now we have
Load A
StoreStore
Store B
Is it possible that the actual execution order is as follows
StoreStore
Store B
Load A
If it is possible, how to explain a situation which seems to violate the The Java volatile Happens-Before Guarantee
.
As far as I know, the volatile semantic is implemented using the following JMM memory barrier addition strategy
insert a StoreStore before volatile variable write operation
insert a StoreLoad after volatile variable write operation
insert a LoadLoad after volatile variable read operation
insert a LoadStore after volatile variable read operation
Now if we have two java threads as follows
thread 1
Load A
StoreStore
Store volatile B
thread 2
Load volatile B
Load C
Accoring to "The Java volatile Happens-Before Guarantee",Load A
should happens-before Load C
when Load volatile B
is after Store volatile B
, but if Load A
can be reordered to "after Store volatile B",how to guarantee Load A is before Load C
?