
On Thursday, 18. November 2010 11:50:55 you wrote:
Or does the mutex/memory barrier ensure the compiler isn't allowed to do register caching?
Ok, quickly checked this with gcc 4.4.4 on linux: -test.c------------------ int *foobar = 0x1234; int a; int main(void) { __sync_synchronize(); a = *foobar; __sync_synchronize(); return *foobar; } ------------------------- gcc -O4 -S test.c: main: .LFB0: .cfi_startproc mfence movq foobar(%rip), %rax movl (%rax), %eax movl %eax, a(%rip) mfence movq foobar(%rip), %rax movl (%rax), %eax ret .cfi_endproc -> The memory barrier invalidates the register cache. Without the second memory barrier in the C source, the compiler uses the register cached value of *foobar. Thanks for your help on this again, Tony. Cheers, Thomas