Difference between Threading.Volatile.Read(Int64) and Threading.Interlocked.Read(Int64)?
Interlocked.Read
translates into a CompareExchange operation:
public static long Read(ref long location){ return Interlocked.CompareExchange(ref location, 0, 0);}
Therefore it has all the benefits of CompareExchange:
- Full memory barrier
- Atomicity
Volatile.Read
on the other hand has only acquire semantics. It helps you ensuring the execution order of your read operations, without any atomicity or freshness guarantee.