The CLR's specified memory model actually mirrors that of the x86/x64
specified memory model. That's why writing to volatile fields while
running on x86/x64 implementations of the CLR results in no-ops,
because, as you say, the x86/x64 memory model specifies store release
fence semantics. Tagging it as volatile simply prevents JIT compiler
level reordering in this case, as you also say. Unfortunately, as of
C# 4, you can't specify longs as being volatile and are required to
use the Thread.VolatileWrite/Read methods, which are quite costly by
comparison, because they will emit full fences (through lock:or/add
instructions I believe). However, as it so happens with the current
x64 JIT compiler implementation, it will not reorder stores (and it
may not even reorder loads at the moment, but I know the x86
implementation did, but I certainly wouldn't count of this). I
believe that Windows only currently runs on processors that support
full cache coherency (x86/x64 and IA64 (I think this is full cache
coherent)), so memory fences aren't required to "flush" caches to make
their contents visible to other processors.
> > Regards, Fil.- Hide quoted text -
>
> - Show quoted text -