Java 易失性读刷新写入和易失性写更新读取
我了解读-获取(不与之后的后续读/写操作重新排序)和写-释放(不与之前的读/写操作重新排序)。我的 q 是:-
- 在读取获取的情况下,它前面的写入操作是否会被刷新?
- 在写入释放的情况下,以前的读取是否会更新?
另外,读-获取是否与易失性读取相同,写入释放是否与 Java 中的易失性写入相同?
为什么这很重要,让我们以写入发布为例。
y = x; // a read.. let's say x is 1 at this point
System.out.println(y);// 1 printed
//or you can also consider System.out.println(x);
write_release_barrier();
//somewhere here, some thread sets x = 2
ready = true;// this is volatile
System.out.println(y);// or maybe, println(x).. what will be printed?
此时,x 是 2 还是 1?在这里,考虑准备好不稳定。我明白,在波动之前的所有商店将首先变得可见。然后只有挥发性才会变得可见。谢谢。
编号:- http://preshing.com/20120913/acquire-and-release-semantics/