Skip to content

Commit

Permalink
[libcxx] [test] Fix spurious failures in the thread join test on Windows
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mstorsjo committed Jul 12, 2021
1 parent 0ec8120 commit d5d4777
Showing 1 changed file with 9 additions and 1 deletion.
Expand Up @@ -19,10 +19,13 @@
#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_;
Expand All @@ -45,7 +48,7 @@ class G
int G::n_alive = 0;
bool G::op_run = false;

void foo() {}
void foo() { done = true; }

int main(int, char**)
{
Expand All @@ -72,6 +75,11 @@ 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

Expand Down

0 comments on commit d5d4777

Please sign in to comment.