title: Interlocked.Read/Exchange for longs on 64-bit architectures
body: <p>Is <code>Interlocked.Read(ref long)</code> "optimized away" on 64-bit architectures? I.e. if I am writing a library which could be used by both architectures, should I be concerned about performance impact of using <code>Interlocked.Read</code> unnecessarily on 64-bit CPUs?</p>
  
  <p>I thought about using something like this, so I am wondering if this makes sense:</p>
  
  <pre><code>    // X64 is a preprocessor constant set for x64 builds  
  
      [MethodImpl(MethodImplOptions.AggressiveInlining)]
      public static long Read(ref long address)
      {
  #if X64
          // atomic on 64-bit processors
          return address;
  #else
          // if I got it right, this creates a full memory barrier
          return Interlocked.Read(ref address);
  #endif
      }
  
      [MethodImpl(MethodImplOptions.AggressiveInlining)]
      public static void Write(ref long address, long value)
      {
  #if X64
          // atomic on 64-bit processors
          address = value;
  #else
          // if I got it right, this creates a full memory barrier
          Interlocked.Exchange(ref address, value);
  #endif
      }
  </code></pre>