title: Do I need to make both variables volatile in reader/writer scenario?
body: <p>We have 2 threads. One is a reader. The other is a writer thread who share these 2 variables:</p>
  
  <pre><code>Object data
  boolean ready
  </code></pre>
  
  <p>Do I need to make both volatile? Is it sufficient to make 'ready' volatile?</p>
  
  <pre><code>write() {
      data = &lt;some data&gt;
      ready = true;
  }
  
  read() {
      if (ready) {
          consume(data);
          ready = false;
      } 
  }
  </code></pre>
  
  <p>Do I need to make both variables volatile?</p>
  
  <p>Based on my limited understnding of the java memory model, I think I only have to make 'ready' volatile as all the code before reading/writing 'ready' happens-before the code after the reading/writing of 'ready' variable?</p>
  
  <p>Update: For the purposes of this question, assume that atomicity is not an issue. The production and consumption of data is atomic.</p>