Hi
All,
C# has
a keyword named "volatile". This keyword is used to mark a
particular object "volatile" . i.e. the value of this object can change any time
in the program by any other thread or process and thus the system always reads
the current value of such an object as the value of this object will never be
cached.
This modifier is generally used if there are multiple threads using the same
object without using the "lock" keyword. Using the volatile modifier ensures
that all threads retrieve the latest value of the object.
Using volatile key word does not solve the thread synchronization
problem.
Objects which can be marked volatile can be :
- Any reference type.
- Any pointer type (in an unsafe context).
- Datatypes like 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.
-- Please post your queries and comments for my
articles in the usergroup for the benefit of all. I hope this step from my end
is helpful to all of us.
Regards,
Namratha (Nasha). |