https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110016
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #15 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Rachel Mant from comment #14) > To properly understand this problem space, why do you think locking the > mutex before setting `finished` is sufficient to fix this? It feels to us > like it shouldn't, and should only mask the bug, making it less likely to > trigger? So currently wait (and the check of finished) is under the mutex, workMutex. If you want to modify finish, it needs to be under the same mutex. Note https://en.cppreference.com/w/cpp/thread/condition_variable mentiones the exact fix too. And even has the following: "Even if the shared variable is atomic, it must be modified while owning the mutex to correctly publish the modification to the waiting thread." (this part was added back in 2015: https://en.cppreference.com/mwiki/index.php?title=cpp/thread/condition_variable&diff=81211&oldid=80448 ) So I think I can now close this as invalid.