[libcxx-commits] [PATCH] D105736: [libcxx] [test] Fix spurious failures in the thread join test on Windows
Martin Storsjö via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jul 9 14:07:40 PDT 2021
mstorsjo created this revision.
mstorsjo added a reviewer: ldionne.
Herald added a subscriber: jfb.
mstorsjo requested review of this revision.
Herald added a project: libc++.
Herald added a reviewer: libc++.
Make sure that the detached thread has started up before exiting
the process.
This is exactly the same fix as D105592 <https://reviews.llvm.org/D105592>, with the same pattern
being present in a different test case.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D105736
Files:
libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/join.pass.cpp
Index: libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/join.pass.cpp
===================================================================
--- libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/join.pass.cpp
+++ libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/join.pass.cpp
@@ -23,6 +23,8 @@
#include "make_test_thread.h"
#include "test_macros.h"
+std::atomic_bool done(false);
+
class G
{
int alive_;
@@ -45,7 +47,7 @@
int G::n_alive = 0;
bool G::op_run = false;
-void foo() {}
+void foo() { done = true; }
int main(int, char**)
{
@@ -72,6 +74,11 @@
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105736.357632.patch
Type: text/x-patch
Size: 1061 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210709/24ee6055/attachment.bin>
More information about the libcxx-commits
mailing list