Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Thread::VolatileWrite Method (UInt16%, UInt16)

 

Writes a value to a field immediately, so that the value is visible to all processors in the computer.

This API is not CLS-compliant.

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

public:
[CLSCompliantAttribute(false)]
static void VolatileWrite(
	unsigned short% address,
	unsigned short value
)

Parameters

address
Type: System::UInt16%

The field to which the value is to be written.

value
Type: System::UInt16

The value to be written.

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, VolatileWrite ensures that a value written to a memory location is immediately visible to all processors. 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.

System_CAPS_noteNote

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

.NET Framework
Available since 1.1
Return to top
Show:
© 2017 Microsoft