title: Thread safety with atomic operations in multi core environment
body: <p>I heard that a single atomic operation is thread-safe because when a core is processing an atomic operation the core wouldn't be doing anything else before it completes that atomic operation .</p>
  
  <p>for example in java in a 32 bit operating system say there is a variable accessible to multiple Threads </p>
  
  <pre><code> int a; 
  </code></pre>
  
  <p>thread 1 write in a</p>
  
  <pre><code>a = 3; 
  </code></pre>
  
  <p>and thread 2 can write </p>
  
  <pre><code>a = 4; 
  </code></pre>
  
  <p>the order of the threads writing to that variable may change so the final value can either be 3 or 4 but we can be sure that writing to an int is an atomic operation so the 32 bits in that variable won't be mixed up in to some unpredictable number </p>
  
  <p>I get that this is the case in a single core environment since the core would not be executing a code of another thread before it is sure that the atomic operation is complete,</p>
  
  <p>however in a multi core environment isn't it possible that another core accesses the variable that is under an atomic operation of the current core?  thus causing the 32bits in the variable to get mixed up? </p>