title: checking for parallel completion using volatile only
body: <p>Consider these shared flags indicating the completion of two different tasks:</p>
  
  <pre><code>volatile boolean completed1 = false;
  volatile boolean completed2 = false;
  </code></pre>
  
  <p>Now consider two threads:</p>
  
  <p>No. 1:</p>
  
  <pre><code>completed1 = true;
  if (completed1 &amp;&amp; completed2) continueSomeOtherStuff();
  </code></pre>
  
  <p>No. 2:</p>
  
  <pre><code>completed2 = true;
  if (completed1 &amp;&amp; completed2) continueSomeOtherStuff();
  </code></pre>
  
  <p>Will continueSomeOtherStuff() be reliably called at least once?</p>
  
  <p>Update:</p>
  
  <p>Found it in the definition of <strong>happens-before</strong> in <a href="http://www.cs.umd.edu/~pugh/java/memoryModel/jsr133.pdf" rel="nofollow noreferrer">http://www.cs.umd.edu/~pugh/java/memoryModel/jsr133.pdf</a> :</p>
  
  <ul>
  <li>Each action in a thread happens-before every subsequent action in that thread.</li>
  <li>An unlock on a monitor happens-before every subsequent lock on that monitor.</li>
  <li><strong>A write to a volatile field happens-before every subsequent read of that volatile.</strong></li>
  </ul>
  
  <p>No thread relation is mentioned in that last sentence so I assume it is meant to be valid across all threads.</p>