title: Is there LoadStore memory barrier before volatile write in JAVA
body: <p>In JSR 133 cook book <a href="http://g.oswego.edu/dl/jmm/cookbook.html" rel="nofollow noreferrer">http://g.oswego.edu/dl/jmm/cookbook.html</a></p>
  <p>In the chapter of inserting barriers:</p>
  <blockquote>
  <p>-Issue a StoreStore barrier before each volatile store.</p>
  <p>-Issue a StoreStore barrier after all stores but before return from any constructor for any class with a final field.</p>
  <p>-Issue a StoreLoad barrier after each volatile store.</p>
  <p>-Issue LoadLoad and LoadStore barriers after each volatile load.</p>
  <p>-Issue an ExitEnter barrier either before each MonitorEnter or after each MonitorExit.</p>
  <p>-Issue EnterLoad and EnterStore barriers after each MonitorEnter.</p>
  <p>-Issue StoreExit and LoadExit barriers before each MonitorExit.</p>
  <p>-If on a processor that does not intrinsically provide ordering on indirect loads, issue a LoadLoad barrier before each load of a final
  fields.</p>
  </blockquote>
  <p>But, no loadstore barrier before volatile write? So load can be reordered after volatile write?</p>
  <p>So the following won't work?</p>
  <pre><code>Init a = 3
  V = false
  
  Thread1
  x = a
  V = true
  
  Thread2
  If (V equal true)
      a = -1
  </code></pre>
  <p>Where V is volatile and a is an ordinary var.</p>
  <p>Thread 1 may read a to x as -1?
  This obey the happen before rule because if Thread2 read V as ture, x = a happen before a = -1?</p>