[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
Mon Jul 12 13:32:41 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd5d477780cf8: [libcxx] [test] Fix spurious failures in the thread join test on Windows (authored by mstorsjo).

Repository:
  rG LLVM Github Monorepo

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

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
@@ -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 @@
 int G::n_alive = 0;
 bool G::op_run = false;
 
-void foo() {}
+void foo() { done = true; }
 
 int main(int, char**)
 {
@@ -72,6 +75,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.358053.patch
Type: text/x-patch
Size: 1149 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210712/a45bc7de/attachment.bin>


More information about the libcxx-commits mailing list