https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63140
--- Comment #11 from Ralf Hoffmann <gcc at boomerangsworld dot de> --- I managed to create a standalone test program. Attachment "aguix.cc" contains the stripped down critical code segments. The two other files "aguixtest.cc" and "aguixtest.hh" are just to make a runnable binary. The attached script "build" can be used to create the binary. The expected output is: wait4mess2 called waittime2: 5 Worker: msg lock element lost! Worker: msg lock element lost! wait4mess2 called (this is what the binary does with gcc 4.8.1) while with gcc 4.9.1 it will loop forever: wait4mess2 called waittime2: 5 waittime2: 5 waittime2: 5 waittime2: 5 .... Compiled with -O1 instead of -O2 the example program crashes. Adding -fsanitize=undefined on the other hand will make it work again regardless of O1 or O2.