Subj : Re: [.NET] Volatile Fields To : comp.programming.threads From : David Hopwood Date : Sat Sep 17 2005 02:44 pm Cool Guy wrote: > David Schwartz wrote: > >>>Shouldn't Test.result be declared as volatile aswell? My understanding is >>>that it should because otherwise the write to it in Thread2 might not be >>>visible to other threads, since the value may be written to a cache >>>instead of to main memory. >> >> It does not have to be on this platform because, as the page says: > > > > See, this is where my understanding goes out of the window. > > From reading that page it seems there's only one issue here: that > reads/writes can be re-ordered and thus just making *one* of those fields > volatile is sufficient. > > But my understanding is that that there are in fact *two* (separate) issues > here: > > a. the above; and > b. that reads may come from a cache instead of from main memory (and > that writes may go to a cache instead of to main memory). The .NET memory model requires cache coherency (actually it doesn't mention caches at all, which is the same thing as requiring them to be a transparent optimization). -- David Hopwood .