http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46096
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-10-20 14:29:09 UTC --- Using a mutex around the reads and writes of shared data will make it work as expected, the compiler won't optimise away the read and will re-read the value every time.