title: How to understand happens-before consistent
body: <p>In <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html#jls-17.4.5" rel="noreferrer">chapter 17 of JLS</a>, it introduce a concept: happens-before consistent.</p>
  
  <blockquote>
    <p>A set of actions A is happens-before consistent if for all reads r in A, where W(r) is the write action seen by r, it is not the case that either hb(r, W(r)) or that there exists a write w in A such that w.v = r.v and hb(W(r), w) and hb(w, r)"</p>
  </blockquote>
  
  <p>In my understanding, it equals to following words:
  ..., it is the case that neither ... nor ...</p>
  
  <p>So my first two questions are:</p>
  
  <ul>
  <li>is my understanding right?</li>
  <li>what does "w.v = r.v" mean?</li>
  </ul>
  
  <p>It also gives an Example: 17.4.5-1</p>
  
  <pre class="lang-none prettyprint-override"><code>Thread 1 Thread 2
  
  B = 1; A = 2; 
  
  r2 = A; r1 = B; 
  </code></pre>
  
  <p>In first execution order:</p>
  
  <pre class="lang-none prettyprint-override"><code>1: B = 1;
  
  3: A = 2;
  
  2: r2 = A;  // sees initial write of 0
  
  4: r1 = B;  // sees initial write of 0
  </code></pre>
  
  <p>The order itself has already told us that two threads are executed alternately, so my third question is: what does left number mean?</p>
  
  <p>In my understanding, the reason of both r2 and r1 can see initial write of 0 is both A and B are not volatile field. So my fourth quesiton is: whether my understanding is right?</p>
  
  <p>In second execution order:</p>
  
  <pre class="lang-none prettyprint-override"><code>1: r2 = A;  // sees write of A = 2
  
  3: r1 = B;  // sees write of B = 1
  
  2: B = 1;
  
  4: A = 2;
  </code></pre>
  
  <p>According to definition of happens-before consistency, it is not difficult to understand this execution order is happens-before consistent(if my first understanding is correct).
  So my fifth and sixth questions are: does it exist this situation (reads see writes that occur later) in real world? If it does, could you give me a real example?</p>