Subj : Re: [.NET] Volatile Fields [correction] To : comp.programming.threads From : Sean Kelly Date : Mon Sep 19 2005 05:49 pm Cool Guy wrote: > David Hopwood wrote: > > > The write to Y is not performed as a single atomic event; it has to be modelled > > as two events: "Y = 1 is performed with respect to processor 2" and "Y = 1 is > > performed with respect to processor 3". So it can happen that processor 2 sees > > Y == 1 before writing Z = 1, but processor 3 does not see Y == 1 until after > > it sees Z == 1. > > > > So it's impossible to make such code thread-safe, then? Simply by following the (sparsely) documented x86 memory model? Yes. Though Alexander suggested a method that should work on existing CPUs: replace load instructions with CMPXCHG. This relies on a comment in the docs for CMPXCHG that says a write is always performed when this instruction is executed, even if the value is not changed as a result of the operation. Hardware folks may argue that this is an implementation detail however (as Andy Glew did), so future x86 CPUs may not guarantee the same behavior. Sean .