title: Does one assembler instruction always execute atomically?
body: <p>Today I came across this question:</p>
  
  <p>you have a code</p>
  
  <pre><code>static int counter = 0;
  void worker() {
      for (int i = 1; i &lt;= 10; i++)
          counter++;
  }
  </code></pre>
  
  <p>If <code>worker</code> would be called from two different threads, what value will <code>counter</code> have after both of them are finished?</p>
  
  <p>I know that actually it could be anything. But my internal guts tells me, that <code>counter++</code> will most likely be translated into single assembler instruction, and if both threads are execute on the same core, <code>counter</code> will be 20.</p>
  
  <p>But what if those threads are run on different cores or processors, could there be a race condition in their microcode? Is one assembler instruction could always be viewed as atomic operation?</p>