[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
Sat Jul 10 12:09:21 PDT 2021


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

Add a missing <atomic> to appease the modules build.


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.357744.patch
Type: text/x-patch
Size: 1149 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210710/d01cccbe/attachment.bin>


More information about the libcxx-commits mailing list