From: "Dave Korn" <[EMAIL PROTECTED]> Date: Mon, 29 Oct 2007 01:16:07 -0000
> Thing is, if you disable all optimisations that are potentially > unsafe in the presence of threads, won't you just get the same > effect as if you had used volatile anyway, only on every single > variable in the program instead of just the ones the programmer has > designated as sensitive? This is not really what is being suggested at all. The compiler simply cannot speculatively load or store to variables with global visibility. Suggesting volatile is totally impractical and in fact overkill. Even basic correct single-threaded UNIX programs are broken by these speculative stores. If I use a conditional test to protect access to memory mmap()'d with a read-only attribute, GCC's optimization will cause write-protection exceptions.