我明白讀取獲取(不會對其後的讀取/寫入操作進行重新排序)和寫入釋放(不會對其前面的讀取/寫入操作進行重新排序)。 我的問題是: -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/