Labels

Monday, June 11, 2007

Volatile Specifier in C#

http://msdn2.microsoft.com/en-us/library/x13ttww7(vs.71).aspx

http://msdn2.microsoft.com/en-us/library/aa645755(VS.71).aspx

The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock statement to serialize access. Using the volatile modifier ensures that one thread retrieves the most up-to-date value written by another thread.

The volatile keyword indicates that a field can be modified in the program by something such as the operating system, the hardware, or a concurrently executing thread.

The system always reads the current value of a volatile object at the point it is requested, even if the previous instruction asked for a value from the same object. Also, the value of the object is written immediately on assignment.

The type of a field marked as volatile is restricted to the following types:

· Any reference type.

· Any pointer type (in an unsafe context).

· The types sbyte, byte, short, ushort, int, uint, char, float, bool.

· An enum type with an enum base type of byte, sbyte, short, ushort, int, or uint.

Thanks & Regards,

Arun Manglick

No comments:

Post a Comment