现在我们有
Load A
StoreStore
Store B
是否有可能实际的执行顺序如下
StoreStore
Store B
Load A
如果可能的话,如何解释似乎违反的情况The Java volatile Happens-Before Guarantee。
据我所知,易失性语义是使用以下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-Beforeguarantee》,Load A应该happens-before Load Cwhen Load volatile Bis after Store volatile B,但是如果Load A可以重新排序到“after Store volatile B”,如何保证Load A is before Load C?
慕勒3428872
有只小跳蛙
相关分类