Does the Java Memory Model guarantee visibility of intra-thread writes?
<p>Consider a simple, single-threaded Java program execution involving no synchronization actions, just plain reads and writes of instance variables. An implementation that simply <strong>ignores all writes</strong> seems to comply with the Java Memory Specification. First, the applicable general statement from <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html#jls-17.4">§17.4</a>:</p>

<blockquote>
  <p>The memory model determines what values can be read at every point in the program. The actions of each thread in isolation must behave as governed by the semantics of that thread, with the exception that the values seen by each read are determined by the memory model.</p>
</blockquote>

<p>The relevant constraints would be the following (<a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html#jls-17.4.5">§17.4.5</a>):</p>

<h3>1. happens-before ordering induced by program order:</h3>

<blockquote>
  <p>If x and y are actions of the same thread and x comes before y in program order, then hb(x, y).</p>
</blockquote>

<h3>2. happens-before consistency:</h3>

<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>This basically precludes a read <em>happening-before</em> the write it observes. The other provision is just a sanity clause that prevents a read of some <code>v</code> seeing an earlier write of that <code>v</code> that was in the meantime followed by another write of the same <code>v</code>.</p>

<p>I cannot find any guarantee whatsoever that a write will positively be observed, only restrictions on what writes may not be observed.</p>

<p>What am I missing here? Is it really possible that the JVM leaves out such a trivial guarantee?</p>
