Make sure that the detached thread has started up before exiting
the process.
This is exactly the same fix as D105592, with the same pattern
being present in a different test case.
Differential Revision: https://reviews.llvm.org/D105736
#include <cstdlib>
#include <cassert>
#include <system_error>
+#include <atomic>
#include "make_test_thread.h"
#include "test_macros.h"
+std::atomic_bool done(false);
+
class G
{
int alive_;
int G::n_alive = 0;
bool G::op_run = false;
-void foo() {}
+void foo() { done = true; }
int main(int, char**)
{
assert(false);
} catch (std::system_error const&) {
}
+ // Wait to make sure that the detached thread has started up.
+ // Without this, we could exit main and start destructing global
+ // resources that are needed when the thread starts up, while the
+ // detached thread would start up only later.
+ while (!done) {}
}
#endif