Well, the problem is exactly that if some value is in a CPU register, calling MemoryBarrier() is not going to update it. You need to call MemoryBarrier() and then also reload the new consistent value from memory (more specifically, from cache that is now known to be consistent with memory) to the CPU register. Since the compiler/optimizer makes the decisions about what and when is going from the memory to the CPU registers, you need to communicate the idea of careful treatment your variable to the compiler. The keyword "volatile" does that.
no subject
Date: 2007-04-12 08:47 pm (UTC)