[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:19:05 PDT 2021


mstorsjo updated this revision to Diff 357075.
mstorsjo added a comment.

Added a comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105592/new/

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,11 @@
             t0.detach();
         } 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: D105592.357075.patch
Type: text/x-patch
Size: 1131 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210707/41c63202/attachment.bin>


More information about the libcxx-commits mailing list