[libcxx-commits] [libcxx] d5d4777 - [libcxx] [test] Fix spurious failures in the thread join test on Windows
Martin Storsjö via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jul 12 13:32:39 PDT 2021
Author: Martin Storsjö
Date: 2021-07-12T23:31:53+03:00
New Revision: d5d477780cf8ffb418975742d837bb2ccb5837f7
URL: https://github.com/llvm/llvm-project/commit/d5d477780cf8ffb418975742d837bb2ccb5837f7
DIFF: https://github.com/llvm/llvm-project/commit/d5d477780cf8ffb418975742d837bb2ccb5837f7.diff
LOG: [libcxx] [test] Fix spurious failures in the thread join test on Windows
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
Added:
Modified:
libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/join.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/join.pass.cpp b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/join.pass.cpp
index 184b931dff84d..2286f74eda72f 100644
--- a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/join.pass.cpp
+++ b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/join.pass.cpp
@@ -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_;
@@ -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**)
{
@@ -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
More information about the libcxx-commits
mailing list