This documentation is archived and is not being maintained.

Thread.VolatileRead Method (Int32)

.NET Framework 1.1
Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

Reads the value of a field. The value is the latest written by any processor in a computer, regardless of the number of processors or the state of processor cache.

[Visual Basic]
Overloads Public Shared Function VolatileRead( _
   ByRef address As Integer _
) As Integer
public static int VolatileRead(
   ref int address
public: static int VolatileRead(
 int* address
public static function VolatileRead(
   address : int
) : int;


The field to be read.

Return Value

The latest value written to the field by any processor.


VolatileRead and VolatileWrite are for special cases of synchronization. Under normal circumstances, the C# lock statement, the Visual Basic SyncLock statement, and the Monitor class provide easier alternatives.

On a multiprocessor system, VolatileRead obtains the very latest value written to a memory location by any processor. This might require flushing processor caches.

Even on a uniprocessor system, VolatileRead and VolatileWrite ensure that a value is read or written to memory, and not cached (for example, in a processor register). Thus, you can use them to synchronize access to a field that can be updated by another thread, or by hardware.

Calling this method affects only a single memory access. To provide effective synchronization for a field, all access to the field must use VolatileRead or VolatileWrite.

Note   In C#, using the volatile modifier on a field guarantees that all access to that field uses VolatileRead or VolatileWrite.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard

See Also

Thread Class | Thread Members | System.Threading Namespace | Thread.VolatileRead Overload List