title: How understand the result of incrementing and printing a global variable by two threads?
body: <p>In my main I have two threads running the following function:</p>
  <pre><code>int i = 0;    
  
  void foo()
  {
     ++i;
     printf(&quot;%d&quot;, i);
  }
  </code></pre>
  <p>I ran it 10000 times and I had 3 different results:
  {1 2}, {1 1}, {2 1}</p>
  <p>First two I understand. The question is how the result can be {2 1} and why {2 2} doesn't appear at all.</p>
  <p>Thank you!</p>