A volatile declaration indicates that a field can be modified in a program by OS, Hardware (mouse, modem) or a thread
System reads the current value of the volatile object at the point it is requested
Value of the object is written immediately on assignment
Usually used for a field that is accessed by multiple threads without using the lock statement
Code Listing: Volatile
// csharp_volatile.cs
class Test
{
public volatile int i;
Test(int _i)
{
i = _i;
}
public static void Main()
{
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment