title: C++ Multi-threading: Visible side-effects of non-atomic variables
body: <p>There is a part in the C++ standard about multi-threading memory model that I don't understand.</p>
  <blockquote>
  <p>A <strong>visible side effect</strong> A on a scalar object or bit-field M with respect to a value computation B of M satisfies the conditions:</p>
  <ul>
  <li><p>A <em>happens before</em> B and</p>
  </li>
  <li><p>there is no other side effect X to M such that A <em>happens before</em> X and X <em>happens before</em> B.</p>
  </li>
  </ul>
  <p>The value of a <strong>non-atomic</strong> scalar object or bit-field M, as determined by evaluation B, <strong>shall be the value stored by the visible side effect A</strong>.</p>
  </blockquote>
  <p>And also according to the C++ standard, a &quot;<em>happens before</em>&quot; relationship between threads must be established by &quot;<em>synchronizes with</em>&quot; or &quot;<em>is dependency-ordered before</em>&quot;, so a &quot;<em>happens before</em>&quot; relationship will not be established without inter-thread synchronization.</p>
  <p>Now suppose there are two threads T1 and T2, both started by the main thread and never do any synchronization with each other (so there would not be any &quot;<em>happens before</em>&quot; relationships established between T1 and T2). If T1 writes to a <strong>non-atomic</strong> variable M, then according to the quote above, T2 should never see M modified by T1, because there is no &quot;<em>happens before</em>&quot; relationship between T1 and T2.</p>
  <p>Instead, T2 has &quot;<em>synchronizes with</em>&quot; relationship established with the main thread at the time T2 starts, so T2 should see the value of M set by the main thread before it was started by the main thread, because there is a &quot;<em>happens before</em>&quot; relationship between the main thread and T2.</p>
  <p>Right? However I did an experiment on my machine and it was not the case. What is wrong?</p>