我明白读取获取(不会对其后的读取/写入操作进行重新排序)和写入释放(不会对其前面的读取/写入操作进行重新排序)。 我的问题是: -Java易失性读取刷新写入和易失性写入更新读取
- 在读取获取的情况下,执行它之前的写入刷新?
- 在写入释放的情况下,先前的读取是否更新?
此外,是读取获取相同的易失性读取,并释放相同的易失性写在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/