Subj : Re: [.NET] Volatile Fields To : comp.programming.threads From : Joe Seigh Date : Sat Sep 17 2005 08:52 am 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). Cache has no effect on read/write ordering. It's the memory model that does. You could have a system without cache and it would still have the same issues with read/write ordering. So trying to imagine what is happening with a hardware entity, which by definition you can't see, only serves to confuse yourself. -- Joe Seigh When you get lemons, you make lemonade. When you get hardware, you make software. .