https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77744
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> --- The std::thread example is similar, but not the same. The OpenMP version shares f, so is equivalent to creating the std::thread objects with std::ref(f). More importantly, the OpenMP version does not wait for the loop to finish (or at least, I see "#pragma omp for nowait" in the GIMPLE dump), so there is no happens-before relation between the loop body and the reTest destructor. I see the same races using: for(unsigned i = 0; i < 10; ++i) std::thread{std::ref(f)}.detach();