What is Volatile Keyword in C# ?

  1. It is a user mode primitive (utilizes CPU Resource) used fr atomic updates.
  2. It tells the compiler not to optimize the code.
  3. It tells the Threads to access the value directly from main memory and do not trust the value cached elsewhere.

Methods In Volatile :  

Volatile.Read and Volatile.Write .They take overloaded arguments of int,bool,short,enum.

public int m_flag=0;
Volatile.Write(ref m_flag, 1);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s