title: volatile boolean
body: <p>If I have a volatile boolean (let's call it valid), is the following piece of code thread-safe in Java?</p>
  
  <pre><code>if (valid)
    return;
  valid = true;
  </code></pre>
  
  <p>Or, do I need to synchronize since valid is set to true only if it's false (hence set of valid depends on its current value)?  </p>