System.Threading.Volatile Class

Contains methods for performing volatile memory operations.

See Also: Volatile Members


public static class Volatile


On a multiprocessor system, a volatile write operation ensures that a value written to a memory location is immediately visible to all processors. A volatile read operation obtains the very latest value written to a memory location by any processor. These operations might require flushing processor caches, which can affect performance.


On a uniprocessor system, volatile reads and writes ensure that a value is read or written to memory and not cached (for example, in a processor register). Thus, you can use these operations to synchronize access to a field that can be updated by another thread or by hardware.

Volatile memory operations are for special cases of synchronization, where normal locking is not an acceptable alternative. Under normal circumstances, the C# lock statement, the Visual Basic SyncLock statement, and the System.Threading.Monitor class provide the easiest and least error-prone way of synchronizing access to data, and the Lazy`1 class provides a simple way to write lazy initialization code without directly using double-checked locking.

The Volatile.Read(Byte@) and Volatile.Write(Byte@, byte) methods enable functionality that is not supported in languages. For example:


Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: