On Mon, Oct 29, 2007 at 22:30:20 +0100, Eric Botcazou wrote: > See gcc/gthr-posix.h for a proper use of "volatile" for a shared access.
It was already shown that you can't use volatile in general case, because you can't pass such data to any function. See the mail of Bart Van Assche. The use doesn't become proper simply because it appears in the code, even if in the code of GCC. volatile might be used there for completely different reasons. Consider this comment: static volatile int __gthread_active = -1; ... /* This test is not protected to avoid taking a lock on the main code path so every update of __gthread_active in a threaded program must be atomic with regard to the result of the test. */ if (__builtin_expect (__gthread_active_latest_value < 0, 0)) { ... volatile + atomic update + cache-coherent system will indeed give you the correct result, but such use is not POSIX-compliant, and I mostly talk about POSIX Threads. -- Tomash Brechko