----------------------------------------------------------- New Message on BDOTNET
----------------------------------------------------------- From: Sriram_Krishnan Message 3 in Discussion The only thing that volatile does is to set up a memory barrier before reads and writes. It works something like this - x86 has something we call a 'weak memory model'. This means that the processor is free to do any damn thing with the variables as long as the output is correct - this includes optimization by putting it into registers,etc. But this creates problems when you have multiple threads - as someone else may come in and change the variable without you knowing it. So my setting up a memory barrier, you explicity tell the runtime not to reorder any reads or writes. This is needed more on a multiproc machine than on a single proc machine actually. Do read Chris Brumme's excellent post on .NET memory models Sriram ----------------------------------------------------------------------------- I blog at http://www.dotnetjunkies.com/weblog/sriram ---------------------------------------------------------------------------- From: Nasha [mailto:[EMAIL PROTECTED] Sent: 21 October 2004 09:55 To: BDOTNET Subject: Article -- "Volatile" C# Keyword New Message on BDOTNET Article -- "Volatile" C# Keyword Reply Reply to Sender Recommend Message 1 in Discussion From: Nasha 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). View other groups in this category. ----------------------------------------------------------- To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings. http://groups.msn.com/bdotnet/_emailsettings.msnw Need help? If you've forgotten your password, please go to Passport Member Services. http://groups.msn.com/_passportredir.msnw?ppmprop=help For other questions or feedback, go to our Contact Us page. http://groups.msn.com/contact If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list. mailto:[EMAIL PROTECTED]
