Export (0) Print
Expand All

Thread.VolatileRead Method (UIntPtr)

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.

This API is not CLS-compliant. 

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

'Declaration
<CLSCompliantAttribute(False)> _
Public Shared Function VolatileRead ( _
	ByRef address As UIntPtr _
) As UIntPtr

Parameters

address
Type: System.UIntPtr

The field to be read.

Return Value

Type: System.UIntPtr
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.

NoteNote

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

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft