[libcxx-commits] [PATCH] D105592: [libcxx] [test] Fix spurious failures in the thread detach test on Windows
Martin Storsjö via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 7 14:12:51 PDT 2021
mstorsjo created this revision.
mstorsjo added a reviewer: ldionne.
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.
If the detached thread hasn't started up at all, and the main thread
exists, global data structures in the process are torn down, which
then can cause crashes when the thread starts up late after required
mutexes have been destroyed. (In particular, the mutex used internally
in _Init_thread_header, which is used in the intialization of
__thread_local_data()::__p, can cause crashes if the main thread already
has finished and progressed far with destruction.)
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D105592
Files:
libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/detach.pass.cpp
Index: libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/detach.pass.cpp
===================================================================
--- libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/detach.pass.cpp
+++ libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/detach.pass.cpp
@@ -60,7 +60,7 @@
int G::n_alive = 0;
bool G::op_run = false;
-void foo() {}
+void foo() { done = true; }
int main(int, char**)
{
@@ -75,6 +75,7 @@
assert(G::n_alive == 1);
}
assert(G::n_alive == 0);
+ done = false;
#ifndef TEST_HAS_NO_EXCEPTIONS
{
std::thread t0 = support::make_test_thread(foo);
@@ -85,6 +86,7 @@
t0.detach();
} catch (std::system_error const&) {
}
+ while (!done) {}
}
#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105592.357072.patch
Type: text/x-patch
Size: 855 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210707/4b54701d/attachment.bin>
More information about the libcxx-commits
mailing list