现在我们有
Load A
StoreStore
Store B
有没有可能实际的执行顺序如下
StoreStore
Store B
Load A
如果可能,如何解释似乎违反The Java volatile Happens-Before Guarantee
.
据我所知,volatile语义是使用下面的JMM内存屏障添加策略实现的
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
现在如果我们有两个java线程如下
线程 1
Load A
StoreStore
Store volatile B
线程 2
Load volatile B
Load C
根据“The Java volatile Happens-Before Guarantee”,<code>Load A应该是happens-before Load C
when Load volatile B
is after Store volatile B
,但如果Load A
可以重新排序为“after Store volatile B”,如何保证Load A is before Load C
?