title: Why is this assignment not thread-safe?
body: <p>I've been reading this book from Joseph Albahari about threading:<br>
  <a href="http://www.albahari.com/threading/" rel="noreferrer">http://www.albahari.com/threading/</a></p>
  
  <p>In Part 2, I found this example:<br>
  <a href="http://www.albahari.com/threading/part2.aspx#_When_to_Lock" rel="noreferrer">http://www.albahari.com/threading/part2.aspx#_When_to_Lock</a></p>
  
  <p>Here is the aforementioned example:</p>
  
  <pre><code>class ThreadUnsafe
  {
    static int _x;
    static void Increment() { _x++; }
    static void Assign()    { _x = 123; }
  }
  </code></pre>
  
  <p>Thread-safe version:</p>
  
  <pre><code>class ThreadSafe
  {
    static readonly object _locker = new object();
    static int _x;
  
    static void Increment() { lock (_locker) _x++; }
    static void Assign()    { lock (_locker) _x = 123; }
  }
  </code></pre>
  
  <p>I couldn't understand why <em>Assign</em> method is not thread safe. Shouldn't integer assignment be atomic operation on both 32- and 64-bit architectures?</p>