https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78158
Dmitry Vyukov <dvyukov at google dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dvyukov at google dot com --- Comment #1 from Dmitry Vyukov <dvyukov at google dot com> --- I can reproduce it with g++ (GCC) 6.0.0 20151206 (experimental). The only combination of flags that produces the race is: g++ /tmp/test.cc -fsanitize=thread -std=c++14 -O0 -DNDEBUG With higher optimization levels the race goes away. Without -DNDEBUG the race goes away. I think NDEBUG is red herring, it just removes the additional atomic loads in asserts and thus removes additional synchronization that masks the race.