[libcxx-commits] [libcxx] 5646280 - [libc++] Introduce an indirection to create threads in the test suite

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Nov 27 08:56:48 PST 2020


Author: Louis Dionne
Date: 2020-11-27T11:54:19-05:00
New Revision: 564628014c404bf57aa7cd9a5337198046bdd1ed

URL: https://github.com/llvm/llvm-project/commit/564628014c404bf57aa7cd9a5337198046bdd1ed
DIFF: https://github.com/llvm/llvm-project/commit/564628014c404bf57aa7cd9a5337198046bdd1ed.diff

LOG: [libc++] Introduce an indirection to create threads in the test suite

We create threads using std::thread in various places in the test suite.
However, the usual std::thread constructor may not work on all platforms,
e.g. on platforms where passing a stack size is required to create a thread.

This commit introduces a simple indirection that makes it easier to tweak
how threads are created inside the test suite on various platforms. Note
that tests that are purposefully calling std::thread's constructor directly
(e.g. because that is what they're testing) were not modified.

Added: 
    libcxx/test/support/make_test_thread.h

Modified: 
    libcxx/test/libcxx/utilities/memory/util.smartptr/race_condition.pass.cpp
    libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.wait/atomic_wait.pass.cpp
    libcxx/test/std/thread/futures/futures.promise/set_exception_at_thread_exit.pass.cpp
    libcxx/test/std/thread/futures/futures.promise/set_lvalue_at_thread_exit.pass.cpp
    libcxx/test/std/thread/futures/futures.promise/set_rvalue_at_thread_exit.pass.cpp
    libcxx/test/std/thread/futures/futures.promise/set_value_at_thread_exit_const.pass.cpp
    libcxx/test/std/thread/futures/futures.promise/set_value_at_thread_exit_void.pass.cpp
    libcxx/test/std/thread/futures/futures.shared_future/get.pass.cpp
    libcxx/test/std/thread/futures/futures.shared_future/wait.pass.cpp
    libcxx/test/std/thread/futures/futures.shared_future/wait_for.pass.cpp
    libcxx/test/std/thread/futures/futures.shared_future/wait_until.pass.cpp
    libcxx/test/std/thread/futures/futures.task/futures.task.members/dtor.pass.cpp
    libcxx/test/std/thread/futures/futures.task/futures.task.members/make_ready_at_thread_exit.pass.cpp
    libcxx/test/std/thread/futures/futures.task/futures.task.members/operator.pass.cpp
    libcxx/test/std/thread/futures/futures.unique_future/get.pass.cpp
    libcxx/test/std/thread/futures/futures.unique_future/wait.pass.cpp
    libcxx/test/std/thread/futures/futures.unique_future/wait_for.pass.cpp
    libcxx/test/std/thread/futures/futures.unique_future/wait_until.pass.cpp
    libcxx/test/std/thread/thread.barrier/arrive.pass.cpp
    libcxx/test/std/thread/thread.barrier/arrive_and_drop.pass.cpp
    libcxx/test/std/thread/thread.barrier/arrive_and_wait.pass.cpp
    libcxx/test/std/thread/thread.barrier/completion.pass.cpp
    libcxx/test/std/thread/thread.condition/notify_all_at_thread_exit.pass.cpp
    libcxx/test/std/thread/thread.condition/thread.condition.condvar/destructor.pass.cpp
    libcxx/test/std/thread/thread.condition/thread.condition.condvar/notify_all.pass.cpp
    libcxx/test/std/thread/thread.condition/thread.condition.condvar/notify_one.pass.cpp
    libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait.pass.cpp
    libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_for.pass.cpp
    libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_for_pred.pass.cpp
    libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_pred.pass.cpp
    libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_until.pass.cpp
    libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_until_pred.pass.cpp
    libcxx/test/std/thread/thread.condition/thread.condition.condvarany/destructor.pass.cpp
    libcxx/test/std/thread/thread.condition/thread.condition.condvarany/notify_all.pass.cpp
    libcxx/test/std/thread/thread.condition/thread.condition.condvarany/notify_one.pass.cpp
    libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait.pass.cpp
    libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for.pass.cpp
    libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for_pred.pass.cpp
    libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_pred.pass.cpp
    libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_terminates.sh.cpp
    libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_until.pass.cpp
    libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_until_pred.pass.cpp
    libcxx/test/std/thread/thread.latch/arrive_and_wait.pass.cpp
    libcxx/test/std/thread/thread.latch/count_down.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_duration.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_time_point.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_try_to_lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_duration.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_time_point.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_try_to_lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/try_lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/try_lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock_shared.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/try_lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/try_lock_shared.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock_shared.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_for.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_for.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_until.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until_deadlock_bug.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock_for.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock_until.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock_for.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock_until.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.once/thread.once.callonce/race.pass.cpp
    libcxx/test/std/thread/thread.semaphore/acquire.pass.cpp
    libcxx/test/std/thread/thread.semaphore/binary.pass.cpp
    libcxx/test/std/thread/thread.semaphore/release.pass.cpp
    libcxx/test/std/thread/thread.semaphore/timed.pass.cpp
    libcxx/test/std/thread/thread.semaphore/try_acquire.pass.cpp
    libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.algorithm/swap.pass.cpp
    libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.assign/copy.compile.fail.cpp
    libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.assign/move.pass.cpp
    libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.assign/move2.pass.cpp
    libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/constr.compile.fail.cpp
    libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/copy.compile.fail.cpp
    libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/move.pass.cpp
    libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.destr/dtor.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/get_id.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/joinable.pass.cpp
    libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/swap.pass.cpp
    libcxxabi/test/guard_threaded_test.pass.cpp
    libcxxabi/test/test_guard.pass.cpp
    libcxxabi/test/thread_local_destruction_order.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/libcxx/utilities/memory/util.smartptr/race_condition.pass.cpp b/libcxx/test/libcxx/utilities/memory/util.smartptr/race_condition.pass.cpp
index 0f7096d5f17e..5ea05cd20d5e 100644
--- a/libcxx/test/libcxx/utilities/memory/util.smartptr/race_condition.pass.cpp
+++ b/libcxx/test/libcxx/utilities/memory/util.smartptr/race_condition.pass.cpp
@@ -20,6 +20,7 @@
 #include <thread>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 typedef std::shared_ptr<int> Ptr;
@@ -51,7 +52,7 @@ void run_test(Ptr p) {
     assert(p.use_count() == 2);
     TestRunner r(p);
     assert(p.use_count() == 3);
-    std::thread t1(r); // Start the test thread.
+    std::thread t1 = support::make_test_thread(r); // Start the test thread.
     assert(p.use_count() == 4);
     Start = true;
     // Run until we witness 25 use count changes via both

diff  --git a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.wait/atomic_wait.pass.cpp b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.wait/atomic_wait.pass.cpp
index b5a345d7fbe2..32929bd4bc7d 100644
--- a/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.wait/atomic_wait.pass.cpp
+++ b/libcxx/test/std/atomics/atomics.types.operations/atomics.types.operations.wait/atomic_wait.pass.cpp
@@ -27,6 +27,7 @@
 #include <cassert>
 #include <thread>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 #include "../atomics.types.operations.req/atomic_helpers.h"
 
@@ -39,23 +40,23 @@ struct TestFn {
     std::atomic_init(&t, T(1));
     assert(std::atomic_load(&t) == T(1));
     std::atomic_wait(&t, T(0));
-    std::thread t_([&](){
+    std::thread t1 = support::make_test_thread([&](){
       std::atomic_store(&t, T(3));
       std::atomic_notify_one(&t);
     });
     std::atomic_wait(&t, T(1));
-    t_.join();
+    t1.join();
 
     volatile A vt;
     std::atomic_init(&vt, T(2));
     assert(std::atomic_load(&vt) == T(2));
     std::atomic_wait(&vt, T(1));
-    std::thread t2_([&](){
+    std::thread t2 = support::make_test_thread([&](){
       std::atomic_store(&vt, T(4));
       std::atomic_notify_one(&vt);
     });
     std::atomic_wait(&vt, T(2));
-    t2_.join();
+    t2.join();
   }
 };
 

diff  --git a/libcxx/test/std/thread/futures/futures.promise/set_exception_at_thread_exit.pass.cpp b/libcxx/test/std/thread/futures/futures.promise/set_exception_at_thread_exit.pass.cpp
index 8c877531670c..ab666641d139 100644
--- a/libcxx/test/std/thread/futures/futures.promise/set_exception_at_thread_exit.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.promise/set_exception_at_thread_exit.pass.cpp
@@ -19,6 +19,7 @@
 #include <future>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 void func(std::promise<int> p)
@@ -32,7 +33,7 @@ int main(int, char**)
         typedef int T;
         std::promise<T> p;
         std::future<T> f = p.get_future();
-        std::thread(func, std::move(p)).detach();
+        support::make_test_thread(func, std::move(p)).detach();
         try
         {
             f.get();

diff  --git a/libcxx/test/std/thread/futures/futures.promise/set_lvalue_at_thread_exit.pass.cpp b/libcxx/test/std/thread/futures/futures.promise/set_lvalue_at_thread_exit.pass.cpp
index 1589493f3738..d3e1da2197a9 100644
--- a/libcxx/test/std/thread/futures/futures.promise/set_lvalue_at_thread_exit.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.promise/set_lvalue_at_thread_exit.pass.cpp
@@ -19,6 +19,7 @@
 #include <memory>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 int i = 0;
@@ -34,7 +35,7 @@ int main(int, char**)
     {
         std::promise<int&> p;
         std::future<int&> f = p.get_future();
-        std::thread(func, std::move(p)).detach();
+        support::make_test_thread(func, std::move(p)).detach();
         assert(f.get() == 4);
     }
 

diff  --git a/libcxx/test/std/thread/futures/futures.promise/set_rvalue_at_thread_exit.pass.cpp b/libcxx/test/std/thread/futures/futures.promise/set_rvalue_at_thread_exit.pass.cpp
index f0ac893b6de6..5a982eabab8d 100644
--- a/libcxx/test/std/thread/futures/futures.promise/set_rvalue_at_thread_exit.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.promise/set_rvalue_at_thread_exit.pass.cpp
@@ -18,6 +18,7 @@
 #include <memory>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 void func(std::promise<std::unique_ptr<int>> p)
@@ -30,7 +31,7 @@ int main(int, char**)
     {
         std::promise<std::unique_ptr<int>> p;
         std::future<std::unique_ptr<int>> f = p.get_future();
-        std::thread(func, std::move(p)).detach();
+        support::make_test_thread(func, std::move(p)).detach();
         assert(*f.get() == 5);
     }
 

diff  --git a/libcxx/test/std/thread/futures/futures.promise/set_value_at_thread_exit_const.pass.cpp b/libcxx/test/std/thread/futures/futures.promise/set_value_at_thread_exit_const.pass.cpp
index 55f7764e5206..da9b7a8d8d0d 100644
--- a/libcxx/test/std/thread/futures/futures.promise/set_value_at_thread_exit_const.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.promise/set_value_at_thread_exit_const.pass.cpp
@@ -18,6 +18,7 @@
 #include <future>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 void func(std::promise<int> p)
@@ -31,7 +32,7 @@ int main(int, char**)
     {
         std::promise<int> p;
         std::future<int> f = p.get_future();
-        std::thread(func, std::move(p)).detach();
+        support::make_test_thread(func, std::move(p)).detach();
         assert(f.get() == 5);
     }
 

diff  --git a/libcxx/test/std/thread/futures/futures.promise/set_value_at_thread_exit_void.pass.cpp b/libcxx/test/std/thread/futures/futures.promise/set_value_at_thread_exit_void.pass.cpp
index 0ba0d6094088..9786973c0c6c 100644
--- a/libcxx/test/std/thread/futures/futures.promise/set_value_at_thread_exit_void.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.promise/set_value_at_thread_exit_void.pass.cpp
@@ -19,6 +19,7 @@
 #include <memory>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 int i = 0;
@@ -34,7 +35,7 @@ int main(int, char**)
     {
         std::promise<void> p;
         std::future<void> f = p.get_future();
-        std::thread(func, std::move(p)).detach();
+        support::make_test_thread(func, std::move(p)).detach();
         f.get();
         assert(i == 1);
     }

diff  --git a/libcxx/test/std/thread/futures/futures.shared_future/get.pass.cpp b/libcxx/test/std/thread/futures/futures.shared_future/get.pass.cpp
index 4b2c8979c939..61835df782cd 100644
--- a/libcxx/test/std/thread/futures/futures.shared_future/get.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.shared_future/get.pass.cpp
@@ -20,6 +20,7 @@
 #include <future>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 void func1(std::promise<int> p)
@@ -68,7 +69,7 @@ int main(int, char**)
         {
             std::promise<T> p;
             std::shared_future<T> f = p.get_future();
-            std::thread(func1, std::move(p)).detach();
+            support::make_test_thread(func1, std::move(p)).detach();
             assert(f.valid());
             assert(f.get() == 3);
             assert(f.valid());
@@ -77,7 +78,7 @@ int main(int, char**)
         {
             std::promise<T> p;
             std::shared_future<T> f = p.get_future();
-            std::thread(func2, std::move(p)).detach();
+            support::make_test_thread(func2, std::move(p)).detach();
             try
             {
                 assert(f.valid());
@@ -97,7 +98,7 @@ int main(int, char**)
         {
             std::promise<T> p;
             std::shared_future<T> f = p.get_future();
-            std::thread(func3, std::move(p)).detach();
+            support::make_test_thread(func3, std::move(p)).detach();
             assert(f.valid());
             assert(f.get() == 5);
             assert(f.valid());
@@ -106,7 +107,7 @@ int main(int, char**)
         {
             std::promise<T> p;
             std::shared_future<T> f = p.get_future();
-            std::thread(func4, std::move(p)).detach();
+            support::make_test_thread(func4, std::move(p)).detach();
             try
             {
                 assert(f.valid());
@@ -126,7 +127,7 @@ int main(int, char**)
         {
             std::promise<T> p;
             std::shared_future<T> f = p.get_future();
-            std::thread(func5, std::move(p)).detach();
+            support::make_test_thread(func5, std::move(p)).detach();
             assert(f.valid());
             f.get();
             assert(f.valid());
@@ -135,7 +136,7 @@ int main(int, char**)
         {
             std::promise<T> p;
             std::shared_future<T> f = p.get_future();
-            std::thread(func6, std::move(p)).detach();
+            support::make_test_thread(func6, std::move(p)).detach();
             try
             {
                 assert(f.valid());

diff  --git a/libcxx/test/std/thread/futures/futures.shared_future/wait.pass.cpp b/libcxx/test/std/thread/futures/futures.shared_future/wait.pass.cpp
index 485d0050de62..4be8c1bd7015 100644
--- a/libcxx/test/std/thread/futures/futures.shared_future/wait.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.shared_future/wait.pass.cpp
@@ -18,6 +18,7 @@
 #include <future>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 void func1(std::promise<int> p)
@@ -49,7 +50,7 @@ int main(int, char**)
         typedef int T;
         std::promise<T> p;
         std::shared_future<T> f = p.get_future();
-        std::thread(func1, std::move(p)).detach();
+        support::make_test_thread(func1, std::move(p)).detach();
         assert(f.valid());
         f.wait();
         assert(f.valid());
@@ -63,7 +64,7 @@ int main(int, char**)
         typedef int& T;
         std::promise<T> p;
         std::shared_future<T> f = p.get_future();
-        std::thread(func3, std::move(p)).detach();
+        support::make_test_thread(func3, std::move(p)).detach();
         assert(f.valid());
         f.wait();
         assert(f.valid());
@@ -77,7 +78,7 @@ int main(int, char**)
         typedef void T;
         std::promise<T> p;
         std::shared_future<T> f = p.get_future();
-        std::thread(func5, std::move(p)).detach();
+        support::make_test_thread(func5, std::move(p)).detach();
         assert(f.valid());
         f.wait();
         assert(f.valid());

diff  --git a/libcxx/test/std/thread/futures/futures.shared_future/wait_for.pass.cpp b/libcxx/test/std/thread/futures/futures.shared_future/wait_for.pass.cpp
index 8f58f1f46c86..d8b0ce3457bc 100644
--- a/libcxx/test/std/thread/futures/futures.shared_future/wait_for.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.shared_future/wait_for.pass.cpp
@@ -20,6 +20,7 @@
 #include <future>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 typedef std::chrono::milliseconds ms;
@@ -56,7 +57,7 @@ int main(int, char**)
     typedef int T;
     std::promise<T> p;
     std::shared_future<T> f = p.get_future();
-    std::thread(func1, std::move(p)).detach();
+    support::make_test_thread(func1, std::move(p)).detach();
     assert(f.valid());
     assert(f.wait_for(ms(1)) == std::future_status::timeout);
     assert(f.valid());
@@ -69,7 +70,7 @@ int main(int, char**)
     typedef int& T;
     std::promise<T> p;
     std::shared_future<T> f = p.get_future();
-    std::thread(func3, std::move(p)).detach();
+    support::make_test_thread(func3, std::move(p)).detach();
     assert(f.valid());
     assert(f.wait_for(ms(1)) == std::future_status::timeout);
     assert(f.valid());
@@ -82,7 +83,7 @@ int main(int, char**)
     typedef void T;
     std::promise<T> p;
     std::shared_future<T> f = p.get_future();
-    std::thread(func5, std::move(p)).detach();
+    support::make_test_thread(func5, std::move(p)).detach();
     assert(f.valid());
     assert(f.wait_for(ms(1)) == std::future_status::timeout);
     assert(f.valid());
@@ -97,7 +98,7 @@ int main(int, char**)
     std::promise<T> p;
     std::shared_future<T> f = p.get_future();
     Clock::time_point t0 = Clock::now();
-    std::thread(func1, std::move(p)).detach();
+    support::make_test_thread(func1, std::move(p)).detach();
     assert(f.valid());
     assert(f.wait_for(ms(1)) == std::future_status::timeout);
     assert(f.valid());
@@ -113,7 +114,7 @@ int main(int, char**)
     std::promise<T> p;
     std::shared_future<T> f = p.get_future();
     Clock::time_point t0 = Clock::now();
-    std::thread(func3, std::move(p)).detach();
+    support::make_test_thread(func3, std::move(p)).detach();
     assert(f.valid());
     assert(f.wait_for(ms(1)) == std::future_status::timeout);
     assert(f.valid());
@@ -129,7 +130,7 @@ int main(int, char**)
     std::promise<T> p;
     std::shared_future<T> f = p.get_future();
     Clock::time_point t0 = Clock::now();
-    std::thread(func5, std::move(p)).detach();
+    support::make_test_thread(func5, std::move(p)).detach();
     assert(f.valid());
     assert(f.wait_for(ms(1)) == std::future_status::timeout);
     assert(f.valid());

diff  --git a/libcxx/test/std/thread/futures/futures.shared_future/wait_until.pass.cpp b/libcxx/test/std/thread/futures/futures.shared_future/wait_until.pass.cpp
index a9e0dbdba538..1d58dc25f218 100644
--- a/libcxx/test/std/thread/futures/futures.shared_future/wait_until.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.shared_future/wait_until.pass.cpp
@@ -21,6 +21,7 @@
 #include <atomic>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 enum class WorkerThreadState { Uninitialized, AllowedToRun, Exiting };
@@ -71,7 +72,7 @@ int main(int, char**)
     typedef int T;
     std::promise<T> p;
     std::shared_future<T> f = p.get_future();
-    std::thread(func1, std::move(p)).detach();
+    support::make_test_thread(func1, std::move(p)).detach();
     assert(f.valid());
     assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout);
     assert(f.valid());
@@ -89,7 +90,7 @@ int main(int, char**)
     typedef int& T;
     std::promise<T> p;
     std::shared_future<T> f = p.get_future();
-    std::thread(func3, std::move(p)).detach();
+    support::make_test_thread(func3, std::move(p)).detach();
     assert(f.valid());
     assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout);
     assert(f.valid());
@@ -107,7 +108,7 @@ int main(int, char**)
     typedef void T;
     std::promise<T> p;
     std::shared_future<T> f = p.get_future();
-    std::thread(func5, std::move(p)).detach();
+    support::make_test_thread(func5, std::move(p)).detach();
     assert(f.valid());
     assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout);
     assert(f.valid());

diff  --git a/libcxx/test/std/thread/futures/futures.task/futures.task.members/dtor.pass.cpp b/libcxx/test/std/thread/futures/futures.task/futures.task.members/dtor.pass.cpp
index 65bc94cf413a..d626f7424443 100644
--- a/libcxx/test/std/thread/futures/futures.task/futures.task.members/dtor.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.task/futures.task.members/dtor.pass.cpp
@@ -18,6 +18,7 @@
 #include <future>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 class A
@@ -45,7 +46,7 @@ int main(int, char**)
     {
         std::packaged_task<double(int, char)> p(A(5));
         std::future<double> f = p.get_future();
-        std::thread(func, std::move(p)).detach();
+        support::make_test_thread(func, std::move(p)).detach();
         try
         {
             double i = f.get();
@@ -61,7 +62,7 @@ int main(int, char**)
     {
         std::packaged_task<double(int, char)> p(A(5));
         std::future<double> f = p.get_future();
-        std::thread(func2, std::move(p)).detach();
+        support::make_test_thread(func2, std::move(p)).detach();
         assert(f.get() == 105.0);
     }
 

diff  --git a/libcxx/test/std/thread/futures/futures.task/futures.task.members/make_ready_at_thread_exit.pass.cpp b/libcxx/test/std/thread/futures/futures.task/futures.task.members/make_ready_at_thread_exit.pass.cpp
index 571a1bf3684a..b42a632ace75 100644
--- a/libcxx/test/std/thread/futures/futures.task/futures.task.members/make_ready_at_thread_exit.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.task/futures.task.members/make_ready_at_thread_exit.pass.cpp
@@ -18,6 +18,7 @@
 #include <future>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 class A
@@ -85,14 +86,14 @@ int main(int, char**)
     {
         std::packaged_task<double(int, char)> p(A(5));
         std::future<double> f = p.get_future();
-        std::thread(func0, std::move(p)).detach();
+        support::make_test_thread(func0, std::move(p)).detach();
         assert(f.get() == 105.0);
     }
 #ifndef TEST_HAS_NO_EXCEPTIONS
     {
         std::packaged_task<double(int, char)> p(A(5));
         std::future<double> f = p.get_future();
-        std::thread(func1, std::move(p)).detach();
+        support::make_test_thread(func1, std::move(p)).detach();
         try
         {
             f.get();
@@ -106,12 +107,12 @@ int main(int, char**)
     {
         std::packaged_task<double(int, char)> p(A(5));
         std::future<double> f = p.get_future();
-        std::thread(func2, std::move(p)).detach();
+        support::make_test_thread(func2, std::move(p)).detach();
         assert(f.get() == 105.0);
     }
     {
         std::packaged_task<double(int, char)> p;
-        std::thread t(func3, std::move(p));
+        std::thread t = support::make_test_thread(func3, std::move(p));
         t.join();
     }
 #endif

diff  --git a/libcxx/test/std/thread/futures/futures.task/futures.task.members/operator.pass.cpp b/libcxx/test/std/thread/futures/futures.task/futures.task.members/operator.pass.cpp
index 5a9f2a6290be..886deb78cb8a 100644
--- a/libcxx/test/std/thread/futures/futures.task/futures.task.members/operator.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.task/futures.task.members/operator.pass.cpp
@@ -18,6 +18,7 @@
 #include <future>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 class A
@@ -85,14 +86,14 @@ int main(int, char**)
     {
         std::packaged_task<double(int, char)> p(A(5));
         std::future<double> f = p.get_future();
-        std::thread(func0, std::move(p)).detach();
+        support::make_test_thread(func0, std::move(p)).detach();
         assert(f.get() == 105.0);
     }
 #ifndef TEST_HAS_NO_EXCEPTIONS
     {
         std::packaged_task<double(int, char)> p(A(5));
         std::future<double> f = p.get_future();
-        std::thread(func1, std::move(p)).detach();
+        support::make_test_thread(func1, std::move(p)).detach();
         try
         {
             f.get();
@@ -106,13 +107,13 @@ int main(int, char**)
     {
         std::packaged_task<double(int, char)> p(A(5));
         std::future<double> f = p.get_future();
-        std::thread t(func2, std::move(p));
+        std::thread t = support::make_test_thread(func2, std::move(p));
         assert(f.get() == 105.0);
         t.join();
     }
     {
         std::packaged_task<double(int, char)> p;
-        std::thread t(func3, std::move(p));
+        std::thread t = support::make_test_thread(func3, std::move(p));
         t.join();
     }
 #endif

diff  --git a/libcxx/test/std/thread/futures/futures.unique_future/get.pass.cpp b/libcxx/test/std/thread/futures/futures.unique_future/get.pass.cpp
index cb188fa908bc..3262a2b7ce57 100644
--- a/libcxx/test/std/thread/futures/futures.unique_future/get.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.unique_future/get.pass.cpp
@@ -20,6 +20,7 @@
 #include <future>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 void func1(std::promise<int> p)
@@ -68,7 +69,7 @@ int main(int, char**)
         {
             std::promise<T> p;
             std::future<T> f = p.get_future();
-            std::thread(func1, std::move(p)).detach();
+            support::make_test_thread(func1, std::move(p)).detach();
             assert(f.valid());
             assert(f.get() == 3);
             assert(!f.valid());
@@ -77,7 +78,7 @@ int main(int, char**)
         {
             std::promise<T> p;
             std::future<T> f = p.get_future();
-            std::thread(func2, std::move(p)).detach();
+            support::make_test_thread(func2, std::move(p)).detach();
             try
             {
                 assert(f.valid());
@@ -97,7 +98,7 @@ int main(int, char**)
         {
             std::promise<T> p;
             std::future<T> f = p.get_future();
-            std::thread(func3, std::move(p)).detach();
+            support::make_test_thread(func3, std::move(p)).detach();
             assert(f.valid());
             assert(f.get() == 5);
             assert(!f.valid());
@@ -106,7 +107,7 @@ int main(int, char**)
         {
             std::promise<T> p;
             std::future<T> f = p.get_future();
-            std::thread(func4, std::move(p)).detach();
+            support::make_test_thread(func4, std::move(p)).detach();
             try
             {
                 assert(f.valid());
@@ -126,7 +127,7 @@ int main(int, char**)
         {
             std::promise<T> p;
             std::future<T> f = p.get_future();
-            std::thread(func5, std::move(p)).detach();
+            support::make_test_thread(func5, std::move(p)).detach();
             assert(f.valid());
             f.get();
             assert(!f.valid());
@@ -135,7 +136,7 @@ int main(int, char**)
         {
             std::promise<T> p;
             std::future<T> f = p.get_future();
-            std::thread(func6, std::move(p)).detach();
+            support::make_test_thread(func6, std::move(p)).detach();
             try
             {
                 assert(f.valid());

diff  --git a/libcxx/test/std/thread/futures/futures.unique_future/wait.pass.cpp b/libcxx/test/std/thread/futures/futures.unique_future/wait.pass.cpp
index ee550545fbbc..712ee3b9b4a1 100644
--- a/libcxx/test/std/thread/futures/futures.unique_future/wait.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.unique_future/wait.pass.cpp
@@ -18,6 +18,7 @@
 #include <future>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 void func1(std::promise<int> p)
@@ -48,7 +49,7 @@ void test(F func) {
 
     std::promise<T> p;
     std::future<T> f = p.get_future();
-    std::thread(func, std::move(p)).detach();
+    support::make_test_thread(func, std::move(p)).detach();
     assert(f.valid());
     f.wait();
     assert(f.valid());

diff  --git a/libcxx/test/std/thread/futures/futures.unique_future/wait_for.pass.cpp b/libcxx/test/std/thread/futures/futures.unique_future/wait_for.pass.cpp
index 9ba4cd262ea8..2a04ade2592e 100644
--- a/libcxx/test/std/thread/futures/futures.unique_future/wait_for.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.unique_future/wait_for.pass.cpp
@@ -20,6 +20,7 @@
 #include <future>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 typedef std::chrono::milliseconds ms;
@@ -54,7 +55,7 @@ void test(F func, bool waitFirst) {
   std::promise<T> p;
   std::future<T> f = p.get_future();
   Clock::time_point t1, t0 = Clock::now();
-  std::thread(func, std::move(p)).detach();
+  support::make_test_thread(func, std::move(p)).detach();
   assert(f.valid());
   assert(f.wait_for(ms(1)) == std::future_status::timeout);
   assert(f.valid());

diff  --git a/libcxx/test/std/thread/futures/futures.unique_future/wait_until.pass.cpp b/libcxx/test/std/thread/futures/futures.unique_future/wait_until.pass.cpp
index 058102812811..e5171e5f9f1f 100644
--- a/libcxx/test/std/thread/futures/futures.unique_future/wait_until.pass.cpp
+++ b/libcxx/test/std/thread/futures/futures.unique_future/wait_until.pass.cpp
@@ -21,6 +21,7 @@
 #include <atomic>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 enum class WorkerThreadState { Uninitialized, AllowedToRun, Exiting };
@@ -70,7 +71,7 @@ int main(int, char**)
     typedef int T;
     std::promise<T> p;
     std::future<T> f = p.get_future();
-    std::thread(func1, std::move(p)).detach();
+    support::make_test_thread(func1, std::move(p)).detach();
     assert(f.valid());
     assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout);
     assert(f.valid());
@@ -88,7 +89,7 @@ int main(int, char**)
     typedef int& T;
     std::promise<T> p;
     std::future<T> f = p.get_future();
-    std::thread(func3, std::move(p)).detach();
+    support::make_test_thread(func3, std::move(p)).detach();
     assert(f.valid());
     assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout);
     assert(f.valid());
@@ -106,7 +107,7 @@ int main(int, char**)
     typedef void T;
     std::promise<T> p;
     std::future<T> f = p.get_future();
-    std::thread(func5, std::move(p)).detach();
+    support::make_test_thread(func5, std::move(p)).detach();
     assert(f.valid());
     assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout);
     assert(f.valid());

diff  --git a/libcxx/test/std/thread/thread.barrier/arrive.pass.cpp b/libcxx/test/std/thread/thread.barrier/arrive.pass.cpp
index 59a219797a53..c4956b611c68 100644
--- a/libcxx/test/std/thread/thread.barrier/arrive.pass.cpp
+++ b/libcxx/test/std/thread/thread.barrier/arrive.pass.cpp
@@ -25,6 +25,7 @@
 #include <barrier>
 #include <thread>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 int main(int, char**)
@@ -32,7 +33,7 @@ int main(int, char**)
   std::barrier<> b(2);
 
   auto tok = b.arrive();
-  std::thread t([&](){
+  std::thread t = support::make_test_thread([&](){
     (void)b.arrive();
   });
   b.wait(std::move(tok));

diff  --git a/libcxx/test/std/thread/thread.barrier/arrive_and_drop.pass.cpp b/libcxx/test/std/thread/thread.barrier/arrive_and_drop.pass.cpp
index 00f8dfa97b98..b8bcbc993bd4 100644
--- a/libcxx/test/std/thread/thread.barrier/arrive_and_drop.pass.cpp
+++ b/libcxx/test/std/thread/thread.barrier/arrive_and_drop.pass.cpp
@@ -26,13 +26,14 @@
 #include <thread>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 int main(int, char**)
 {
   std::barrier<> b(2);
 
-  std::thread t([&](){
+  std::thread t = support::make_test_thread([&](){
     b.arrive_and_drop();
   });
 

diff  --git a/libcxx/test/std/thread/thread.barrier/arrive_and_wait.pass.cpp b/libcxx/test/std/thread/thread.barrier/arrive_and_wait.pass.cpp
index b3da00eb6e34..8fc546934733 100644
--- a/libcxx/test/std/thread/thread.barrier/arrive_and_wait.pass.cpp
+++ b/libcxx/test/std/thread/thread.barrier/arrive_and_wait.pass.cpp
@@ -25,13 +25,14 @@
 #include <barrier>
 #include <thread>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 int main(int, char**)
 {
   std::barrier<> b(2);
 
-  std::thread t([&](){
+  std::thread t = support::make_test_thread([&](){
     for(int i = 0; i < 10; ++i)
       b.arrive_and_wait();
   });

diff  --git a/libcxx/test/std/thread/thread.barrier/completion.pass.cpp b/libcxx/test/std/thread/thread.barrier/completion.pass.cpp
index 7d4e8119790d..d9200729d97e 100644
--- a/libcxx/test/std/thread/thread.barrier/completion.pass.cpp
+++ b/libcxx/test/std/thread/thread.barrier/completion.pass.cpp
@@ -26,6 +26,7 @@
 #include <thread>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 int main(int, char**)
@@ -34,7 +35,7 @@ int main(int, char**)
   auto comp = [&]() { x += 1; };
   std::barrier<decltype(comp)> b(2, comp);
 
-  std::thread t([&](){
+  std::thread t = support::make_test_thread([&](){
       for(int i = 0; i < 10; ++i)
         b.arrive_and_wait();
   });

diff  --git a/libcxx/test/std/thread/thread.condition/notify_all_at_thread_exit.pass.cpp b/libcxx/test/std/thread/thread.condition/notify_all_at_thread_exit.pass.cpp
index 8ef869b66a96..48a077455b36 100644
--- a/libcxx/test/std/thread/thread.condition/notify_all_at_thread_exit.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/notify_all_at_thread_exit.pass.cpp
@@ -23,6 +23,7 @@
 #include <chrono>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::condition_variable cv;
@@ -41,7 +42,7 @@ void func()
 int main(int, char**)
 {
     std::unique_lock<std::mutex> lk(mut);
-    std::thread t(func);
+    std::thread t = support::make_test_thread(func);
     Clock::time_point t0 = Clock::now();
     cv.wait(lk);
     Clock::time_point t1 = Clock::now();

diff  --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/destructor.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/destructor.pass.cpp
index 1c4eeb94d01b..6f2d6b97fb70 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/destructor.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/destructor.pass.cpp
@@ -19,6 +19,7 @@
 #include <thread>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::condition_variable* cv;
@@ -48,12 +49,12 @@ void g()
 int main(int, char**)
 {
     cv = new std::condition_variable;
-    std::thread th2(g);
+    std::thread th2 = support::make_test_thread(g);
     Lock lk(m);
     while (!g_ready)
         cv->wait(lk);
     lk.unlock();
-    std::thread th1(f);
+    std::thread th1 = support::make_test_thread(f);
     th1.join();
     th2.join();
 

diff  --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/notify_all.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/notify_all.pass.cpp
index f0f614d1c24e..b095cd06e4e4 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/notify_all.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/notify_all.pass.cpp
@@ -19,6 +19,7 @@
 #include <thread>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::condition_variable cv;
@@ -50,8 +51,8 @@ void f2()
 
 int main(int, char**)
 {
-    std::thread t1(f1);
-    std::thread t2(f2);
+    std::thread t1 = support::make_test_thread(f1);
+    std::thread t2 = support::make_test_thread(f2);
     std::this_thread::sleep_for(std::chrono::milliseconds(100));
     {
         std::unique_lock<std::mutex>lk(mut);

diff  --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/notify_one.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/notify_one.pass.cpp
index b37305056517..821fbdda5b62 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/notify_one.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/notify_one.pass.cpp
@@ -41,6 +41,7 @@
 #include <thread>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 
@@ -78,8 +79,8 @@ void f2()
 
 int main(int, char**)
 {
-  std::thread t1(f1);
-  std::thread t2(f2);
+  std::thread t1 = support::make_test_thread(f1);
+  std::thread t2 = support::make_test_thread(f2);
   {
     while (ready > 0)
       std::this_thread::yield();

diff  --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait.pass.cpp
index e89bb313b47c..a2dc4466f0d6 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait.pass.cpp
@@ -19,6 +19,7 @@
 #include <thread>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::condition_variable cv;
@@ -40,8 +41,8 @@ void f()
 
 int main(int, char**)
 {
-    std::unique_lock<std::mutex>lk(mut);
-    std::thread t(f);
+    std::unique_lock<std::mutex> lk(mut);
+    std::thread t = support::make_test_thread(f);
     assert(test1 == 0);
     while (test1 == 0)
         cv.wait(lk);

diff  --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_for.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_for.pass.cpp
index 3bead1b6ff89..a58e15f7b009 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_for.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_for.pass.cpp
@@ -25,6 +25,7 @@
 #include <chrono>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::condition_variable cv;
@@ -64,8 +65,8 @@ void f()
 int main(int, char**)
 {
     {
-        std::unique_lock<std::mutex>lk(mut);
-        std::thread t(f);
+        std::unique_lock<std::mutex> lk(mut);
+        std::thread t = support::make_test_thread(f);
         assert(test1 == 0);
         while (test1 == 0)
             cv.wait(lk);
@@ -78,8 +79,8 @@ int main(int, char**)
     test1 = 0;
     test2 = 0;
     {
-        std::unique_lock<std::mutex>lk(mut);
-        std::thread t(f);
+        std::unique_lock<std::mutex> lk(mut);
+        std::thread t = support::make_test_thread(f);
         assert(test1 == 0);
         while (test1 == 0)
             cv.wait(lk);

diff  --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_for_pred.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_for_pred.pass.cpp
index f3322b9b7c04..d6a1bb922408 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_for_pred.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_for_pred.pass.cpp
@@ -24,6 +24,7 @@
 #include <chrono>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 class Pred
@@ -72,7 +73,7 @@ int main(int, char**)
 {
     {
         std::unique_lock<std::mutex>lk(mut);
-        std::thread t(f);
+        std::thread t = support::make_test_thread(f);
         assert(test1 == 0);
         while (test1 == 0)
             cv.wait(lk);
@@ -86,7 +87,7 @@ int main(int, char**)
     test2 = 0;
     {
         std::unique_lock<std::mutex>lk(mut);
-        std::thread t(f);
+        std::thread t = support::make_test_thread(f);
         assert(test1 == 0);
         while (test1 == 0)
             cv.wait(lk);

diff  --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_pred.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_pred.pass.cpp
index c4034fc2b215..041333e2b633 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_pred.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_pred.pass.cpp
@@ -21,6 +21,7 @@
 #include <functional>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::condition_variable cv;
@@ -51,7 +52,7 @@ void f()
 int main(int, char**)
 {
     std::unique_lock<std::mutex>lk(mut);
-    std::thread t(f);
+    std::thread t = support::make_test_thread(f);
     assert(test1 == 0);
     while (test1 == 0)
         cv.wait(lk);

diff  --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_until.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_until.pass.cpp
index e5c77f28eb84..c41bc5ce9132 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_until.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_until.pass.cpp
@@ -23,6 +23,7 @@
 #include <chrono>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 struct TestClock
@@ -83,7 +84,7 @@ void run_test()
     test2 = 0;
     {
         std::unique_lock<std::mutex>lk(mut);
-        std::thread t(f<Clock>);
+        std::thread t = support::make_test_thread(f<Clock>);
         assert(test1 == 0);
         while (test1 == 0)
             cv.wait(lk);
@@ -97,7 +98,7 @@ void run_test()
     test2 = 0;
     {
         std::unique_lock<std::mutex>lk(mut);
-        std::thread t(f<Clock>);
+        std::thread t = support::make_test_thread(f<Clock>);
         assert(test1 == 0);
         while (test1 == 0)
             cv.wait(lk);

diff  --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_until_pred.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_until_pred.pass.cpp
index ab43bdb1a02a..23b42daaac54 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_until_pred.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvar/wait_until_pred.pass.cpp
@@ -26,6 +26,7 @@
 #include <chrono>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 struct Clock
@@ -90,8 +91,8 @@ void f()
 int main(int, char**)
 {
     {
-        std::unique_lock<std::mutex>lk(mut);
-        std::thread t(f);
+        std::unique_lock<std::mutex> lk(mut);
+        std::thread t = support::make_test_thread(f);
         assert(test1 == 0);
         while (test1 == 0)
             cv.wait(lk);
@@ -104,8 +105,8 @@ int main(int, char**)
     test1 = 0;
     test2 = 0;
     {
-        std::unique_lock<std::mutex>lk(mut);
-        std::thread t(f);
+        std::unique_lock<std::mutex> lk(mut);
+        std::thread t = support::make_test_thread(f);
         assert(test1 == 0);
         while (test1 == 0)
             cv.wait(lk);

diff  --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/destructor.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/destructor.pass.cpp
index 4b9d719ec5d7..7ac99550b11c 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/destructor.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/destructor.pass.cpp
@@ -19,6 +19,7 @@
 #include <thread>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::condition_variable_any* cv;
@@ -49,12 +50,12 @@ void g()
 int main(int, char**)
 {
     cv = new std::condition_variable_any;
-    std::thread th2(g);
+    std::thread th2 = support::make_test_thread(g);
     m.lock();
     while (!g_ready)
         cv->wait(m);
     m.unlock();
-    std::thread th1(f);
+    std::thread th1 = support::make_test_thread(f);
     th1.join();
     th2.join();
 

diff  --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/notify_all.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/notify_all.pass.cpp
index 36428bc7fc50..05825ea26c94 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/notify_all.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/notify_all.pass.cpp
@@ -21,6 +21,7 @@
 #include <atomic>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::condition_variable_any cv;
@@ -46,7 +47,7 @@ int main(int, char**)
   notReady = threadCount;
   std::vector<std::thread> threads(threadCount);
   for (unsigned i = 0; i < threadCount; i++)
-    threads[i] = std::thread(helper);
+    threads[i] = support::make_test_thread(helper);
   {
     while (notReady > 0)
       std::this_thread::yield();

diff  --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/notify_one.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/notify_one.pass.cpp
index 60a7dd7f10f7..66ce0fefd553 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/notify_one.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/notify_one.pass.cpp
@@ -21,6 +21,7 @@
 #include <thread>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::condition_variable_any cv;
@@ -56,8 +57,8 @@ void f2()
 
 int main(int, char**)
 {
-    std::thread t1(f1);
-    std::thread t2(f2);
+    std::thread t1 = support::make_test_thread(f1);
+    std::thread t2 = support::make_test_thread(f2);
     std::this_thread::sleep_for(std::chrono::milliseconds(100));
     {
         L1 lk(m0);

diff  --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait.pass.cpp
index 291fcad827d9..a29fd9d7bd7c 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait.pass.cpp
@@ -20,6 +20,7 @@
 #include <thread>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::condition_variable_any cv;
@@ -46,7 +47,7 @@ void f()
 int main(int, char**)
 {
     L1 lk(m0);
-    std::thread t(f);
+    std::thread t = support::make_test_thread(f);
     assert(test1 == 0);
     while (test1 == 0)
         cv.wait(lk);

diff  --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for.pass.cpp
index d89d54ace951..26535e8a07e1 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for.pass.cpp
@@ -24,6 +24,7 @@
 #include <chrono>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::condition_variable_any cv;
@@ -68,7 +69,7 @@ int main(int, char**)
 {
     {
         L1 lk(m0);
-        std::thread t(f);
+        std::thread t = support::make_test_thread(f);
         assert(test1 == 0);
         while (test1 == 0)
             cv.wait(lk);
@@ -82,7 +83,7 @@ int main(int, char**)
     test2 = 0;
     {
         L1 lk(m0);
-        std::thread t(f);
+        std::thread t = support::make_test_thread(f);
         assert(test1 == 0);
         while (test1 == 0)
             cv.wait(lk);

diff  --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for_pred.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for_pred.pass.cpp
index 7b91efaa950b..75d709d36af8 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for_pred.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_for_pred.pass.cpp
@@ -23,6 +23,7 @@
 #include <chrono>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 class Pred
@@ -77,7 +78,7 @@ int main(int, char**)
     {
         expect_result = true;
         L1 lk(m0);
-        std::thread t(f);
+        std::thread t = support::make_test_thread(f);
         assert(test1 == 0);
         while (test1 == 0)
             cv.wait(lk);
@@ -92,7 +93,7 @@ int main(int, char**)
     {
         expect_result = false;
         L1 lk(m0);
-        std::thread t(f);
+        std::thread t = support::make_test_thread(f);
         assert(test1 == 0);
         while (test1 == 0)
             cv.wait(lk);

diff  --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_pred.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_pred.pass.cpp
index 41bcd80794ed..d32848e3087c 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_pred.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_pred.pass.cpp
@@ -21,6 +21,7 @@
 #include <functional>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::condition_variable_any cv;
@@ -55,7 +56,7 @@ void f()
 int main(int, char**)
 {
     L1 lk(m0);
-    std::thread t(f);
+    std::thread t = support::make_test_thread(f);
     assert(test1 == 0);
     while (test1 == 0)
         cv.wait(lk);

diff  --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_terminates.sh.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_terminates.sh.cpp
index f4bb2b71bc79..c507917b5317 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_terminates.sh.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_terminates.sh.cpp
@@ -63,6 +63,8 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
+
 void my_terminate() {
   std::_Exit(0); // Use _Exit to prevent cleanup from taking place.
 }
@@ -118,7 +120,7 @@ int main(int argc, char **argv) {
   try {
     mut.lock();
     assert(pred == false);
-    std::thread(signal_me).detach();
+    support::make_test_thread(signal_me).detach();
     switch (id) {
       case 1: cv.wait(mut); break;
       case 2: cv.wait(mut, pred_function); break;

diff  --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_until.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_until.pass.cpp
index de48880c7683..8054f0248e8c 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_until.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_until.pass.cpp
@@ -22,6 +22,7 @@
 #include <chrono>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 struct Clock
@@ -81,7 +82,7 @@ int main(int, char**)
 {
     {
         L1 lk(m0);
-        std::thread t(f);
+        std::thread t = support::make_test_thread(f);
         assert(test1 == 0);
         while (test1 == 0)
             cv.wait(lk);
@@ -95,7 +96,7 @@ int main(int, char**)
     test2 = 0;
     {
         L1 lk(m0);
-        std::thread t(f);
+        std::thread t = support::make_test_thread(f);
         assert(test1 == 0);
         while (test1 == 0)
             cv.wait(lk);

diff  --git a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_until_pred.pass.cpp b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_until_pred.pass.cpp
index 1c3e5814d093..74d18d0d7e0c 100644
--- a/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_until_pred.pass.cpp
+++ b/libcxx/test/std/thread/thread.condition/thread.condition.condvarany/wait_until_pred.pass.cpp
@@ -26,6 +26,7 @@
 #include <chrono>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 struct Clock
@@ -95,7 +96,7 @@ int main(int, char**)
 {
     {
         L1 lk(m0);
-        std::thread t(f);
+        std::thread t = support::make_test_thread(f);
         assert(test1 == 0);
         while (test1 == 0)
             cv.wait(lk);
@@ -109,7 +110,7 @@ int main(int, char**)
     test2 = 0;
     {
         L1 lk(m0);
-        std::thread t(f);
+        std::thread t = support::make_test_thread(f);
         assert(test1 == 0);
         while (test1 == 0)
             cv.wait(lk);

diff  --git a/libcxx/test/std/thread/thread.latch/arrive_and_wait.pass.cpp b/libcxx/test/std/thread/thread.latch/arrive_and_wait.pass.cpp
index c4c4b2ea0432..b11d46bbffd9 100644
--- a/libcxx/test/std/thread/thread.latch/arrive_and_wait.pass.cpp
+++ b/libcxx/test/std/thread/thread.latch/arrive_and_wait.pass.cpp
@@ -25,13 +25,14 @@
 #include <latch>
 #include <thread>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 int main(int, char**)
 {
   std::latch l(2);
 
-  std::thread t([&](){
+  std::thread t = support::make_test_thread([&](){
       l.arrive_and_wait();
   });
   l.arrive_and_wait();

diff  --git a/libcxx/test/std/thread/thread.latch/count_down.pass.cpp b/libcxx/test/std/thread/thread.latch/count_down.pass.cpp
index 336b32102cd2..9043dc145599 100644
--- a/libcxx/test/std/thread/thread.latch/count_down.pass.cpp
+++ b/libcxx/test/std/thread/thread.latch/count_down.pass.cpp
@@ -25,6 +25,7 @@
 #include <latch>
 #include <thread>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 int main(int, char**)
@@ -32,7 +33,7 @@ int main(int, char**)
   std::latch l(2);
 
   l.count_down();
-  std::thread t([&](){
+  std::thread t = support::make_test_thread([&](){
     l.count_down();
   });
   l.wait();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex.pass.cpp
index cfffafdce822..3e3560c7e983 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex.pass.cpp
@@ -31,6 +31,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 typedef std::chrono::system_clock Clock;
@@ -82,7 +83,7 @@ int main(int, char**)
     {
         m.lock();
         for (int i = 0; i < 5; ++i)
-            v.push_back(std::thread(f));
+            v.push_back(support::make_test_thread(f));
         std::this_thread::sleep_for(WaitTime);
         m.unlock();
         for (auto& t : v)
@@ -91,8 +92,8 @@ int main(int, char**)
     {
         m.lock_shared();
         for (auto& t : v)
-            t = std::thread(g);
-        std::thread q(f);
+            t = support::make_test_thread(g);
+        std::thread q = support::make_test_thread(f);
         std::this_thread::sleep_for(WaitTime);
         m.unlock_shared();
         for (auto& t : v)

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_duration.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_duration.pass.cpp
index 31643071f1fd..811f4727c9bb 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_duration.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_duration.pass.cpp
@@ -27,6 +27,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::shared_timed_mutex m;
@@ -75,7 +76,7 @@ int main(int, char**)
     m.lock();
     std::vector<std::thread> v;
     for (unsigned i = 0; i < Threads; ++i)
-      v.push_back(std::thread(f1));
+      v.push_back(support::make_test_thread(f1));
     while (CountDown > 0)
       std::this_thread::yield();
     // Give one more chance for threads to block and wait for the mutex.
@@ -89,7 +90,7 @@ int main(int, char**)
     m.lock();
     std::vector<std::thread> v;
     for (unsigned i = 0; i < Threads; ++i)
-      v.push_back(std::thread(f2));
+      v.push_back(support::make_test_thread(f2));
     for (auto& t : v)
       t.join();
     m.unlock();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_time_point.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_time_point.pass.cpp
index f0081c2c2dd8..eb31b2572287 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_time_point.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_time_point.pass.cpp
@@ -27,6 +27,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::shared_timed_mutex m;
@@ -69,7 +70,7 @@ int main(int, char**)
     m.lock();
     std::vector<std::thread> v;
     for (unsigned i = 0; i < Threads; ++i)
-      v.push_back(std::thread(f1));
+      v.push_back(support::make_test_thread(f1));
     while (CountDown > 0)
       std::this_thread::yield();
     std::this_thread::sleep_for(ShortTime);
@@ -81,7 +82,7 @@ int main(int, char**)
     m.lock();
     std::vector<std::thread> v;
     for (unsigned i = 0; i < Threads; ++i)
-      v.push_back(std::thread(f2));
+      v.push_back(support::make_test_thread(f2));
     for (auto& t : v)
       t.join();
     m.unlock();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_try_to_lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_try_to_lock.pass.cpp
index d13eeb860fc3..c12a54828168 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_try_to_lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_try_to_lock.pass.cpp
@@ -28,6 +28,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::shared_timed_mutex m;
@@ -69,7 +70,7 @@ int main(int, char**)
     m.lock();
     std::vector<std::thread> v;
     for (int i = 0; i < 5; ++i)
-        v.push_back(std::thread(f));
+        v.push_back(support::make_test_thread(f));
     std::this_thread::sleep_for(ms(250));
     m.unlock();
     for (auto& t : v)

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp
index 6db3a44c71f5..591b828a2b38 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp
@@ -28,6 +28,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::shared_timed_mutex m;
@@ -90,7 +91,7 @@ int main(int, char**)
     m.lock();
     std::vector<std::thread> v;
     for (int i = 0; i < 5; ++i)
-        v.push_back(std::thread(f));
+        v.push_back(support::make_test_thread(f));
     std::this_thread::sleep_for(WaitTime);
     m.unlock();
     for (auto& t : v)

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex.pass.cpp
index c9e0c671fb74..bd25d02cfe10 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex.pass.cpp
@@ -24,6 +24,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::mutex m;
@@ -49,7 +50,7 @@ void f()
 int main(int, char**)
 {
     m.lock();
-    std::thread t(f);
+    std::thread t = support::make_test_thread(f);
     std::this_thread::sleep_for(ms(250));
     m.unlock();
     t.join();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_duration.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_duration.pass.cpp
index fdc3c8b065b5..1f4e03299417 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_duration.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_duration.pass.cpp
@@ -22,6 +22,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::timed_mutex m;
@@ -56,14 +57,14 @@ int main(int, char**)
 {
     {
         m.lock();
-        std::thread t(f1);
+        std::thread t = support::make_test_thread(f1);
         std::this_thread::sleep_for(ms(250));
         m.unlock();
         t.join();
     }
     {
         m.lock();
-        std::thread t(f2);
+        std::thread t = support::make_test_thread(f2);
         std::this_thread::sleep_for(ms(300));
         m.unlock();
         t.join();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_time_point.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_time_point.pass.cpp
index 2bac8784dbfb..5231c593fd3c 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_time_point.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_time_point.pass.cpp
@@ -22,6 +22,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::timed_mutex m;
@@ -56,14 +57,14 @@ int main(int, char**)
 {
     {
         m.lock();
-        std::thread t(f1);
+        std::thread t = support::make_test_thread(f1);
         std::this_thread::sleep_for(ms(250));
         m.unlock();
         t.join();
     }
     {
         m.lock();
-        std::thread t(f2);
+        std::thread t = support::make_test_thread(f2);
         std::this_thread::sleep_for(ms(300));
         m.unlock();
         t.join();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_try_to_lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_try_to_lock.pass.cpp
index 7aaf5a2955a4..1ebbb6b7e7ea 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_try_to_lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_try_to_lock.pass.cpp
@@ -20,6 +20,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::mutex m;
@@ -59,7 +60,7 @@ void f()
 int main(int, char**)
 {
     m.lock();
-    std::thread t(f);
+    std::thread t = support::make_test_thread(f);
     std::this_thread::sleep_for(ms(250));
     m.unlock();
     t.join();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/lock.pass.cpp
index b5425a79de36..26f82520a89d 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/lock.pass.cpp
@@ -21,6 +21,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::mutex m;
@@ -69,7 +70,7 @@ void f()
 int main(int, char**)
 {
     m.lock();
-    std::thread t(f);
+    std::thread t = support::make_test_thread(f);
     std::this_thread::sleep_for(ms(250));
     m.unlock();
     t.join();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/lock.pass.cpp
index 3c2d15dfd5b8..f375b6fb7d17 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/lock.pass.cpp
@@ -21,6 +21,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::mutex m;
@@ -44,7 +45,7 @@ void f()
 int main(int, char**)
 {
     m.lock();
-    std::thread t(f);
+    std::thread t = support::make_test_thread(f);
     std::this_thread::sleep_for(ms(250));
     m.unlock();
     t.join();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/try_lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/try_lock.pass.cpp
index 5a6715c0c5c4..dc9d6c3ef6d9 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/try_lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/try_lock.pass.cpp
@@ -21,6 +21,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::mutex m;
@@ -48,7 +49,7 @@ void f()
 int main(int, char**)
 {
     m.lock();
-    std::thread t(f);
+    std::thread t = support::make_test_thread(f);
     std::this_thread::sleep_for(ms(250));
     m.unlock();
     t.join();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/lock.pass.cpp
index 2225432aa367..1ce9a4cde192 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/lock.pass.cpp
@@ -20,6 +20,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::recursive_mutex m;
@@ -45,7 +46,7 @@ void f()
 int main(int, char**)
 {
     m.lock();
-    std::thread t(f);
+    std::thread t = support::make_test_thread(f);
     std::this_thread::sleep_for(ms(250));
     m.unlock();
     t.join();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/try_lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/try_lock.pass.cpp
index c0ab6ff5c5c5..60a4da786470 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/try_lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/try_lock.pass.cpp
@@ -21,6 +21,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::recursive_mutex m;
@@ -50,7 +51,7 @@ void f()
 int main(int, char**)
 {
     m.lock();
-    std::thread t(f);
+    std::thread t = support::make_test_thread(f);
     std::this_thread::sleep_for(ms(250));
     m.unlock();
     t.join();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock.pass.cpp
index aed7f6516f11..82715ace50ad 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock.pass.cpp
@@ -27,6 +27,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::shared_mutex m;
@@ -61,7 +62,7 @@ void f()
 int main(int, char**)
 {
     m.lock();
-    std::thread t(f);
+    std::thread t = support::make_test_thread(f);
     std::this_thread::sleep_for(WaitTime);
     m.unlock();
     t.join();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock_shared.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock_shared.pass.cpp
index c2e7fd9bcb38..6c69c2eaa48f 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock_shared.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock_shared.pass.cpp
@@ -28,6 +28,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::shared_mutex m;
@@ -75,15 +76,15 @@ int main(int, char**)
     m.lock();
     std::vector<std::thread> v;
     for (int i = 0; i < 5; ++i)
-        v.push_back(std::thread(f));
+        v.push_back(support::make_test_thread(f));
     std::this_thread::sleep_for(WaitTime);
     m.unlock();
     for (auto& t : v)
         t.join();
     m.lock_shared();
     for (auto& t : v)
-        t = std::thread(g);
-    std::thread q(f);
+        t = support::make_test_thread(g);
+    std::thread q = support::make_test_thread(f);
     std::this_thread::sleep_for(WaitTime);
     m.unlock_shared();
     for (auto& t : v)

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/try_lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/try_lock.pass.cpp
index 9c9f09fd799f..6f39ae442e04 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/try_lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/try_lock.pass.cpp
@@ -27,6 +27,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::shared_mutex m;
@@ -54,7 +55,7 @@ void f()
 int main(int, char**)
 {
     m.lock();
-    std::thread t(f);
+    std::thread t = support::make_test_thread(f);
     std::this_thread::sleep_for(ms(250));
     m.unlock();
     t.join();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/try_lock_shared.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/try_lock_shared.pass.cpp
index c4e18ebb1552..fda9485d659a 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/try_lock_shared.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/try_lock_shared.pass.cpp
@@ -28,6 +28,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::shared_mutex m;
@@ -58,7 +59,7 @@ int main(int, char**)
     m.lock();
     std::vector<std::thread> v;
     for (int i = 0; i < 5; ++i)
-        v.push_back(std::thread(f));
+        v.push_back(support::make_test_thread(f));
     std::this_thread::sleep_for(ms(250));
     m.unlock();
     for (auto& t : v)

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock.pass.cpp
index e17547228f44..2b05c8c7f7d3 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock.pass.cpp
@@ -25,6 +25,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::shared_timed_mutex m;
@@ -54,7 +55,7 @@ void f()
 int main(int, char**)
 {
   m.lock();
-  std::thread t(f);
+  std::thread t = support::make_test_thread(f);
   while (!ready)
     std::this_thread::yield();
   start = Clock::now();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock_shared.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock_shared.pass.cpp
index 5b711708abf5..0d77585a12d5 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock_shared.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock_shared.pass.cpp
@@ -26,6 +26,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::shared_timed_mutex m;
@@ -76,7 +77,7 @@ int main(int, char**)
   m.lock();
   std::vector<std::thread> v;
   for (int i = 0; i < threads; ++i)
-    v.push_back(std::thread(readerMustWait));
+    v.push_back(support::make_test_thread(readerMustWait));
   while (countDown > 0)
     std::this_thread::yield();
   readerStart = Clock::now();
@@ -88,8 +89,8 @@ int main(int, char**)
   countDown.store(threads + 1);
   m.lock_shared();
   for (auto& t : v)
-    t = std::thread(reader);
-  std::thread q(writerMustWait);
+    t = support::make_test_thread(reader);
+  std::thread q = support::make_test_thread(writerMustWait);
   while (countDown > 0)
     std::this_thread::yield();
   writerStart = Clock::now();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock.pass.cpp
index 910f92fdc9f4..97fef9b67d8e 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock.pass.cpp
@@ -27,6 +27,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::shared_timed_mutex m;
@@ -54,7 +55,7 @@ void f()
 int main(int, char**)
 {
     m.lock();
-    std::thread t(f);
+    std::thread t = support::make_test_thread(f);
     std::this_thread::sleep_for(ms(250));
     m.unlock();
     t.join();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_for.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_for.pass.cpp
index 40b840128859..c981f075f604 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_for.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_for.pass.cpp
@@ -28,6 +28,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::shared_timed_mutex m;
@@ -73,14 +74,14 @@ int main(int, char**)
 {
     {
         m.lock();
-        std::thread t(f1);
+        std::thread t = support::make_test_thread(f1);
         std::this_thread::sleep_for(WaitTime);
         m.unlock();
         t.join();
     }
     {
         m.lock();
-        std::thread t(f2);
+        std::thread t = support::make_test_thread(f2);
         std::this_thread::sleep_for(WaitTime + Tolerance);
         m.unlock();
         t.join();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared.pass.cpp
index 24aee00a0723..adef56ca3757 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared.pass.cpp
@@ -28,6 +28,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::shared_timed_mutex m;
@@ -64,7 +65,7 @@ int main(int, char**)
     m.lock();
     std::vector<std::thread> v;
     for (int i = 0; i < 5; ++i)
-        v.push_back(std::thread(f));
+        v.push_back(support::make_test_thread(f));
     std::this_thread::sleep_for(ms(250));
     m.unlock();
     for (auto& t : v)

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_for.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_for.pass.cpp
index 77ef92663288..06966c33c7cf 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_for.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_for.pass.cpp
@@ -29,6 +29,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::shared_timed_mutex m;
@@ -75,7 +76,7 @@ int main(int, char**)
         m.lock();
         std::vector<std::thread> v;
         for (int i = 0; i < 5; ++i)
-            v.push_back(std::thread(f1));
+            v.push_back(support::make_test_thread(f1));
         std::this_thread::sleep_for(WaitTime);
         m.unlock();
         for (auto& t : v)
@@ -85,7 +86,7 @@ int main(int, char**)
         m.lock();
         std::vector<std::thread> v;
         for (int i = 0; i < 5; ++i)
-            v.push_back(std::thread(f2));
+            v.push_back(support::make_test_thread(f2));
         std::this_thread::sleep_for(WaitTime + Tolerance);
         m.unlock();
         for (auto& t : v)

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_until.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_until.pass.cpp
index a9513c83cf1f..a80fb7405c72 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_until.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_until.pass.cpp
@@ -29,6 +29,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::shared_timed_mutex m;
@@ -72,7 +73,7 @@ int main(int, char**)
     m.lock();
     std::vector<std::thread> v;
     for (int i = 0; i < threads; ++i)
-      v.push_back(std::thread(f1));
+      v.push_back(support::make_test_thread(f1));
     while (countDown > 0)
       std::this_thread::yield();
     m.unlock();
@@ -83,7 +84,7 @@ int main(int, char**)
     m.lock();
     std::vector<std::thread> v;
     for (int i = 0; i < threads; ++i)
-      v.push_back(std::thread(f2));
+      v.push_back(support::make_test_thread(f2));
     for (auto& t : v)
       t.join();
     m.unlock();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until.pass.cpp
index edf826827c04..4413a2218e0c 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until.pass.cpp
@@ -28,6 +28,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::shared_timed_mutex m;
@@ -73,14 +74,14 @@ int main(int, char**)
 {
     {
         m.lock();
-        std::thread t(f1);
+        std::thread t = support::make_test_thread(f1);
         std::this_thread::sleep_for(WaitTime);
         m.unlock();
         t.join();
     }
     {
         m.lock();
-        std::thread t(f2);
+        std::thread t = support::make_test_thread(f2);
         std::this_thread::sleep_for(WaitTime + Tolerance);
         m.unlock();
         t.join();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until_deadlock_bug.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until_deadlock_bug.pass.cpp
index e99bb9720ddb..7300dad7d5a2 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until_deadlock_bug.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until_deadlock_bug.pass.cpp
@@ -26,6 +26,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::shared_timed_mutex m;
@@ -59,10 +60,10 @@ int main(int, char**)
   typedef std::chrono::steady_clock Clock;
 
   m.lock_shared();
-  std::thread t1(writer_one);
+  std::thread t1 = support::make_test_thread(writer_one);
   // create some readers
-  std::thread t2(blocked_reader);
-  std::thread t3(blocked_reader);
+  std::thread t2 = support::make_test_thread(blocked_reader);
+  std::thread t3 = support::make_test_thread(blocked_reader);
   // Kill the test after 10 seconds if it hasn't completed.
   auto end_point = Clock::now() + std::chrono::seconds(10);
   while (readers_finished != total_readers && Clock::now() < end_point) {

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/lock.pass.cpp
index 782bf057ebb9..a61fd99368f3 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/lock.pass.cpp
@@ -20,6 +20,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::timed_mutex m;
@@ -43,7 +44,7 @@ void f()
 int main(int, char**)
 {
     m.lock();
-    std::thread t(f);
+    std::thread t = support::make_test_thread(f);
     std::this_thread::sleep_for(ms(250));
     m.unlock();
     t.join();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock.pass.cpp
index 5e5eb1df82f1..30cfcaccf9df 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock.pass.cpp
@@ -20,6 +20,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::timed_mutex m;
@@ -47,7 +48,7 @@ void f()
 int main(int, char**)
 {
     m.lock();
-    std::thread t(f);
+    std::thread t = support::make_test_thread(f);
     std::this_thread::sleep_for(ms(250));
     m.unlock();
     t.join();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock_for.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock_for.pass.cpp
index 4eb435f4dd38..fc757def0bbf 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock_for.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock_for.pass.cpp
@@ -21,6 +21,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::timed_mutex m;
@@ -54,14 +55,14 @@ int main(int, char**)
 {
     {
         m.lock();
-        std::thread t(f1);
+        std::thread t = support::make_test_thread(f1);
         std::this_thread::sleep_for(ms(250));
         m.unlock();
         t.join();
     }
     {
         m.lock();
-        std::thread t(f2);
+        std::thread t = support::make_test_thread(f2);
         std::this_thread::sleep_for(ms(300));
         m.unlock();
         t.join();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock_until.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock_until.pass.cpp
index 02bc366e9aac..85649041c948 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock_until.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock_until.pass.cpp
@@ -21,6 +21,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::timed_mutex m;
@@ -54,14 +55,14 @@ int main(int, char**)
 {
     {
         m.lock();
-        std::thread t(f1);
+        std::thread t = support::make_test_thread(f1);
         std::this_thread::sleep_for(ms(250));
         m.unlock();
         t.join();
     }
     {
         m.lock();
-        std::thread t(f2);
+        std::thread t = support::make_test_thread(f2);
         std::this_thread::sleep_for(ms(300));
         m.unlock();
         t.join();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/lock.pass.cpp
index 98e34370206e..d58cee5d4a9b 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/lock.pass.cpp
@@ -20,6 +20,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::recursive_timed_mutex m;
@@ -45,7 +46,7 @@ void f()
 int main(int, char**)
 {
     m.lock();
-    std::thread t(f);
+    std::thread t = support::make_test_thread(f);
     std::this_thread::sleep_for(ms(250));
     m.unlock();
     t.join();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock.pass.cpp
index 0045414ba4a2..6e36056a736d 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock.pass.cpp
@@ -20,6 +20,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::recursive_timed_mutex m;
@@ -49,7 +50,7 @@ void f()
 int main(int, char**)
 {
     m.lock();
-    std::thread t(f);
+    std::thread t = support::make_test_thread(f);
     std::this_thread::sleep_for(ms(250));
     m.unlock();
     t.join();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock_for.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock_for.pass.cpp
index c1072432d84f..4a9fd3ec522e 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock_for.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock_for.pass.cpp
@@ -21,6 +21,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::recursive_timed_mutex m;
@@ -56,14 +57,14 @@ int main(int, char**)
 {
     {
         m.lock();
-        std::thread t(f1);
+        std::thread t = support::make_test_thread(f1);
         std::this_thread::sleep_for(ms(250));
         m.unlock();
         t.join();
     }
     {
         m.lock();
-        std::thread t(f2);
+        std::thread t = support::make_test_thread(f2);
         std::this_thread::sleep_for(ms(300));
         m.unlock();
         t.join();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock_until.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock_until.pass.cpp
index a2734d229eb6..37e4410c0af9 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock_until.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock_until.pass.cpp
@@ -21,6 +21,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::recursive_timed_mutex m;
@@ -56,14 +57,14 @@ int main(int, char**)
 {
     {
         m.lock();
-        std::thread t(f1);
+        std::thread t = support::make_test_thread(f1);
         std::this_thread::sleep_for(ms(250));
         m.unlock();
         t.join();
     }
     {
         m.lock();
-        std::thread t(f2);
+        std::thread t = support::make_test_thread(f2);
         std::this_thread::sleep_for(ms(300));
         m.unlock();
         t.join();

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp
index 398ee058c128..bcc19eaed1c0 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp
@@ -19,6 +19,7 @@
 #include <thread>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 typedef std::chrono::milliseconds ms;
@@ -190,8 +191,8 @@ int main(int, char**)
 {
     // check basic functionality
     {
-        std::thread t0(f0);
-        std::thread t1(f0);
+        std::thread t0 = support::make_test_thread(f0);
+        std::thread t1 = support::make_test_thread(f0);
         t0.join();
         t1.join();
         assert(init0_called == 1);
@@ -199,8 +200,8 @@ int main(int, char**)
 #ifndef TEST_HAS_NO_EXCEPTIONS
     // check basic exception safety
     {
-        std::thread t0(f3);
-        std::thread t1(f3);
+        std::thread t0 = support::make_test_thread(f3);
+        std::thread t1 = support::make_test_thread(f3);
         t0.join();
         t1.join();
         assert(init3_called == 2);
@@ -209,8 +210,8 @@ int main(int, char**)
 #endif
     // check deadlock avoidance
     {
-        std::thread t0(f41);
-        std::thread t1(f42);
+        std::thread t0 = support::make_test_thread(f41);
+        std::thread t1 = support::make_test_thread(f42);
         t0.join();
         t1.join();
         assert(init41_called == 1);
@@ -219,16 +220,16 @@ int main(int, char**)
 #if TEST_STD_VER >= 11
     // check functors with 1 arg
     {
-        std::thread t0(f1);
-        std::thread t1(f1);
+        std::thread t0 = support::make_test_thread(f1);
+        std::thread t1 = support::make_test_thread(f1);
         t0.join();
         t1.join();
         assert(init1::called == 1);
     }
     // check functors with 2 args
     {
-        std::thread t0(f2);
-        std::thread t1(f2);
+        std::thread t0 = support::make_test_thread(f2);
+        std::thread t1 = support::make_test_thread(f2);
         t0.join();
         t1.join();
         assert(init2::called == 5);

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.once/thread.once.callonce/race.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.once/thread.once.callonce/race.pass.cpp
index 4ff0274c17a4..54d29aec3a93 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.once/thread.once.callonce/race.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.once/thread.once.callonce/race.pass.cpp
@@ -23,6 +23,7 @@
 #include <thread>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::once_flag flg0;
@@ -41,8 +42,8 @@ void f0()
 
 int main(int, char**)
 {
-    std::thread t0(f0);
-    std::thread t1(f0);
+    std::thread t0 = support::make_test_thread(f0);
+    std::thread t1 = support::make_test_thread(f0);
     t0.join();
     t1.join();
     assert(global == 1);

diff  --git a/libcxx/test/std/thread/thread.semaphore/acquire.pass.cpp b/libcxx/test/std/thread/thread.semaphore/acquire.pass.cpp
index f8466ba8a9ee..aea01f32d36b 100644
--- a/libcxx/test/std/thread/thread.semaphore/acquire.pass.cpp
+++ b/libcxx/test/std/thread/thread.semaphore/acquire.pass.cpp
@@ -25,13 +25,14 @@
 #include <semaphore>
 #include <thread>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 int main(int, char**)
 {
   std::counting_semaphore<> s(2);
 
-  std::thread t([&](){
+  std::thread t = support::make_test_thread([&](){
     s.acquire();
   });
   t.join();

diff  --git a/libcxx/test/std/thread/thread.semaphore/binary.pass.cpp b/libcxx/test/std/thread/thread.semaphore/binary.pass.cpp
index 5ef65f381eca..55816858876c 100644
--- a/libcxx/test/std/thread/thread.semaphore/binary.pass.cpp
+++ b/libcxx/test/std/thread/thread.semaphore/binary.pass.cpp
@@ -26,6 +26,7 @@
 #include <chrono>
 #include <thread>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 int main(int, char**)
@@ -40,7 +41,7 @@ int main(int, char**)
     }
   };
 
-  std::thread t(l);
+  std::thread t = support::make_test_thread(l);
   l();
 
   t.join();

diff  --git a/libcxx/test/std/thread/thread.semaphore/release.pass.cpp b/libcxx/test/std/thread/thread.semaphore/release.pass.cpp
index 268514ce342e..b49747b09601 100644
--- a/libcxx/test/std/thread/thread.semaphore/release.pass.cpp
+++ b/libcxx/test/std/thread/thread.semaphore/release.pass.cpp
@@ -25,6 +25,7 @@
 #include <semaphore>
 #include <thread>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 int main(int, char**)
@@ -34,7 +35,7 @@ int main(int, char**)
   s.release();
   s.acquire();
 
-  std::thread t([&](){
+  std::thread t = support::make_test_thread([&](){
     s.acquire();
   });
   s.release(2);

diff  --git a/libcxx/test/std/thread/thread.semaphore/timed.pass.cpp b/libcxx/test/std/thread/thread.semaphore/timed.pass.cpp
index c46dae5f9052..281e3b47ccef 100644
--- a/libcxx/test/std/thread/thread.semaphore/timed.pass.cpp
+++ b/libcxx/test/std/thread/thread.semaphore/timed.pass.cpp
@@ -26,6 +26,7 @@
 #include <thread>
 #include <chrono>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 int main(int, char**)
@@ -37,7 +38,7 @@ int main(int, char**)
   assert(!s.try_acquire_until(start + std::chrono::milliseconds(250)));
   assert(!s.try_acquire_for(std::chrono::milliseconds(250)));
 
-  std::thread t([&](){
+  std::thread t = support::make_test_thread([&](){
     std::this_thread::sleep_for(std::chrono::milliseconds(250));
     s.release();
     std::this_thread::sleep_for(std::chrono::milliseconds(250));

diff  --git a/libcxx/test/std/thread/thread.semaphore/try_acquire.pass.cpp b/libcxx/test/std/thread/thread.semaphore/try_acquire.pass.cpp
index 45cdcd48e2ea..9b387c95e3af 100644
--- a/libcxx/test/std/thread/thread.semaphore/try_acquire.pass.cpp
+++ b/libcxx/test/std/thread/thread.semaphore/try_acquire.pass.cpp
@@ -25,6 +25,7 @@
 #include <semaphore>
 #include <thread>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 int main(int, char**)
@@ -35,7 +36,7 @@ int main(int, char**)
   s.release();
   assert(s.try_acquire());
   s.release(2);
-  std::thread t([&](){
+  std::thread t = support::make_test_thread([&](){
     assert(s.try_acquire());
   });
   t.join();

diff  --git a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.algorithm/swap.pass.cpp b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.algorithm/swap.pass.cpp
index f2cbba6bda5a..332754ae2a52 100644
--- a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.algorithm/swap.pass.cpp
+++ b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.algorithm/swap.pass.cpp
@@ -19,6 +19,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 class G
@@ -47,7 +48,7 @@ int main(int, char**)
 {
     {
         G g;
-        std::thread t0(g);
+        std::thread t0 = support::make_test_thread(g);
         std::thread::id id0 = t0.get_id();
         std::thread t1;
         std::thread::id id1 = t1.get_id();

diff  --git a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.assign/copy.compile.fail.cpp b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.assign/copy.compile.fail.cpp
index e67ceea5db61..9d7e1044be29 100644
--- a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.assign/copy.compile.fail.cpp
+++ b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.assign/copy.compile.fail.cpp
@@ -13,40 +13,11 @@
 // thread& operator=(thread&& t);
 
 #include <thread>
-#include <new>
-#include <cstdlib>
-#include <cassert>
-
-class G
-{
-    int alive_;
-public:
-    static int n_alive;
-    static bool op_run;
-
-    G() : alive_(1) {++n_alive;}
-    G(const G& g) : alive_(g.alive_) {++n_alive;}
-    ~G() {alive_ = 0; --n_alive;}
-
-    void operator()()
-    {
-        assert(alive_ == 1);
-        assert(n_alive >= 1);
-        op_run = true;
-    }
-
-};
-
-int G::n_alive = 0;
-bool G::op_run = false;
 
 int main(int, char**)
 {
-    {
-        std::thread t0(G());
-        std::thread t1;
-        t1 = t0;
-    }
-
-  return 0;
+    std::thread t0;
+    std::thread t1;
+    t0 = t1;
+    return 0;
 }

diff  --git a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.assign/move.pass.cpp b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.assign/move.pass.cpp
index c2104752d0ab..371d8266dc2a 100644
--- a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.assign/move.pass.cpp
+++ b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.assign/move.pass.cpp
@@ -18,6 +18,7 @@
 #include <cassert>
 #include <utility>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 class G
@@ -51,7 +52,7 @@ int main(int, char**)
         assert(G::n_alive == 1);
         assert(!G::op_run);
 
-        std::thread t0(g);
+        std::thread t0 = support::make_test_thread(g);
         std::thread::id id = t0.get_id();
 
         std::thread t1;

diff  --git a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.assign/move2.pass.cpp b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.assign/move2.pass.cpp
index 27cbf3a46693..ccae438018c2 100644
--- a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.assign/move2.pass.cpp
+++ b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.assign/move2.pass.cpp
@@ -20,6 +20,7 @@
 #include <exception>
 #include <utility>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 struct G
@@ -37,7 +38,7 @@ int main(int, char**)
     std::set_terminate(f1);
     {
         G g;
-        std::thread t0(g);
+        std::thread t0 = support::make_test_thread(g);
         std::thread t1;
         t0 = std::move(t1);
         assert(false);

diff  --git a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/constr.compile.fail.cpp b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/constr.compile.fail.cpp
index 26231373f80c..dd472f079044 100644
--- a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/constr.compile.fail.cpp
+++ b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/constr.compile.fail.cpp
@@ -16,12 +16,10 @@
 
 
 #include <thread>
-#include <cassert>
 
 int main(int, char**)
 {
     volatile std::thread t1;
     std::thread t2 ( t1, 1, 2.0 );
-
-  return 0;
+    return 0;
 }

diff  --git a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/copy.compile.fail.cpp b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/copy.compile.fail.cpp
index 2a3632cd42fb..f0e288b3c19c 100644
--- a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/copy.compile.fail.cpp
+++ b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/copy.compile.fail.cpp
@@ -13,55 +13,10 @@
 // thread(const thread&) = delete;
 
 #include <thread>
-#include <new>
-#include <cstdlib>
-#include <cassert>
-
-class G
-{
-    int alive_;
-public:
-    static int n_alive;
-    static bool op_run;
-
-    G() : alive_(1) {++n_alive;}
-    G(const G& g) : alive_(g.alive_) {++n_alive;}
-    ~G() {alive_ = 0; --n_alive;}
-
-    void operator()()
-    {
-        assert(alive_ == 1);
-        assert(n_alive >= 1);
-        op_run = true;
-    }
-
-    void operator()(int i, double j)
-    {
-        assert(alive_ == 1);
-        assert(n_alive >= 1);
-        assert(i == 5);
-        assert(j == 5.5);
-        op_run = true;
-    }
-};
-
-int G::n_alive = 0;
-bool G::op_run = false;
 
 int main(int, char**)
 {
-    {
-        assert(G::n_alive == 0);
-        assert(!G::op_run);
-        std::thread t0(G(), 5, 5.5);
-        std::thread::id id = t0.get_id();
-        std::thread t1 = t0;
-        assert(t1.get_id() == id);
-        assert(t0.get_id() == std::thread::id());
-        t1.join();
-        assert(G::n_alive == 0);
-        assert(G::op_run);
-    }
-
-  return 0;
+    std::thread t0; (void)t0;
+    std::thread t1(t0); (void)t1;
+    return 0;
 }

diff  --git a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/move.pass.cpp b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/move.pass.cpp
index 55265cce9f93..3611fc623d14 100644
--- a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/move.pass.cpp
+++ b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/move.pass.cpp
@@ -19,6 +19,7 @@
 #include <cstdlib>
 #include <utility>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 class G
@@ -52,7 +53,7 @@ int main(int, char**)
         assert(G::n_alive == 1);
         assert(!G::op_run);
 
-        std::thread t0(g);
+        std::thread t0 = support::make_test_thread(g);
         std::thread::id id = t0.get_id();
 
         std::thread t1 = std::move(t0);

diff  --git a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.destr/dtor.pass.cpp b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.destr/dtor.pass.cpp
index 34e0e51b1200..1af063c02e07 100644
--- a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.destr/dtor.pass.cpp
+++ b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.destr/dtor.pass.cpp
@@ -20,6 +20,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 class G
@@ -57,7 +58,7 @@ int main(int, char**)
         assert(!G::op_run);
         G g;
         {
-          std::thread t(g);
+          std::thread t = support::make_test_thread(g);
           std::this_thread::sleep_for(std::chrono::milliseconds(250));
         }
     }

diff  --git a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/detach.pass.cpp b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/detach.pass.cpp
index bf72e3437a47..ea82d5392aeb 100644
--- a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/detach.pass.cpp
+++ b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/detach.pass.cpp
@@ -19,6 +19,7 @@
 #include <system_error>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::atomic_bool done(false);
@@ -65,7 +66,7 @@ int main(int, char**)
 {
     {
         G g;
-        std::thread t0(g);
+        std::thread t0 = support::make_test_thread(g);
         assert(t0.joinable());
         t0.detach();
         assert(!t0.joinable());
@@ -76,7 +77,7 @@ int main(int, char**)
     assert(G::n_alive == 0);
 #ifndef TEST_HAS_NO_EXCEPTIONS
     {
-        std::thread t0(foo);
+        std::thread t0 = support::make_test_thread(foo);
         assert(t0.joinable());
         t0.detach();
         assert(!t0.joinable());

diff  --git a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/get_id.pass.cpp b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/get_id.pass.cpp
index 676666c34262..314b1e072deb 100644
--- a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/get_id.pass.cpp
+++ b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/get_id.pass.cpp
@@ -19,6 +19,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 class G
@@ -47,7 +48,7 @@ int main(int, char**)
 {
     {
         G g;
-        std::thread t0(g);
+        std::thread t0 = support::make_test_thread(g);
         std::thread::id id0 = t0.get_id();
         std::thread t1;
         std::thread::id id1 = t1.get_id();

diff  --git a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/join.pass.cpp b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/join.pass.cpp
index b64a111c6be7..184b931dff84 100644
--- a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/join.pass.cpp
+++ b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/join.pass.cpp
@@ -20,6 +20,7 @@
 #include <cassert>
 #include <system_error>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 class G
@@ -50,7 +51,7 @@ int main(int, char**)
 {
     {
         G g;
-        std::thread t0(g);
+        std::thread t0 = support::make_test_thread(g);
         assert(t0.joinable());
         t0.join();
         assert(!t0.joinable());
@@ -64,7 +65,7 @@ int main(int, char**)
     }
 #ifndef TEST_HAS_NO_EXCEPTIONS
     {
-        std::thread t0(foo);
+        std::thread t0 = support::make_test_thread(foo);
         t0.detach();
         try {
             t0.join();

diff  --git a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/joinable.pass.cpp b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/joinable.pass.cpp
index a2ffe8bb19a2..d3c1405c5a15 100644
--- a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/joinable.pass.cpp
+++ b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/joinable.pass.cpp
@@ -19,6 +19,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 class G
@@ -47,7 +48,7 @@ int main(int, char**)
 {
     {
         G g;
-        std::thread t0(g);
+        std::thread t0 = support::make_test_thread(g);
         assert(t0.joinable());
         t0.join();
         assert(!t0.joinable());

diff  --git a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/swap.pass.cpp b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/swap.pass.cpp
index a1ab4781d95a..f390899aa5d3 100644
--- a/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/swap.pass.cpp
+++ b/libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/swap.pass.cpp
@@ -19,6 +19,7 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 class G
@@ -47,7 +48,7 @@ int main(int, char**)
 {
     {
         G g;
-        std::thread t0(g);
+        std::thread t0 = support::make_test_thread(g);
         std::thread::id id0 = t0.get_id();
         std::thread t1;
         std::thread::id id1 = t1.get_id();

diff  --git a/libcxx/test/support/make_test_thread.h b/libcxx/test/support/make_test_thread.h
new file mode 100644
index 000000000000..3366d126ae22
--- /dev/null
+++ b/libcxx/test/support/make_test_thread.h
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+#ifndef TEST_SUPPORT_MAKE_TEST_THREAD_H
+#define TEST_SUPPORT_MAKE_TEST_THREAD_H
+
+#include <thread>
+#include <utility>
+
+namespace support {
+
+template <class F, class ...Args>
+std::thread make_test_thread(F&& f, Args&& ...args) {
+    return std::thread(std::forward<F>(f), std::forward<Args>(args)...);
+}
+
+} // end namespace support
+
+#endif // TEST_SUPPORT_MAKE_TEST_THREAD_H

diff  --git a/libcxxabi/test/guard_threaded_test.pass.cpp b/libcxxabi/test/guard_threaded_test.pass.cpp
index 7e5e0de8c790..798d11b15d1a 100644
--- a/libcxxabi/test/guard_threaded_test.pass.cpp
+++ b/libcxxabi/test/guard_threaded_test.pass.cpp
@@ -20,6 +20,7 @@
 #include <memory>
 #include <vector>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 
@@ -349,21 +350,21 @@ void test_futex_syscall() {
   int lock1 = 0;
   int lock2 = 0;
   int lock3 = 0;
-  std::thread waiter1([&]() {
+  std::thread waiter1 = support::make_test_thread([&]() {
     int expect = 0;
     PlatformFutexWait(&lock1, expect);
     assert(lock1 == 1);
   });
-  std::thread waiter2([&]() {
+  std::thread waiter2 = support::make_test_thread([&]() {
     int expect = 0;
     PlatformFutexWait(&lock2, expect);
     assert(lock2 == 2);
   });
-  std::thread waiter3([&]() {
+  std::thread waiter3 = support::make_test_thread([&]() {
     int expect = 42; // not the value
     PlatformFutexWait(&lock3, expect); // doesn't block
   });
-  std::thread waker([&]() {
+  std::thread waker = support::make_test_thread([&]() {
     lock1 = 1;
     PlatformFutexWake(&lock1);
     lock2 = 2;

diff  --git a/libcxxabi/test/test_guard.pass.cpp b/libcxxabi/test/test_guard.pass.cpp
index 2168986c455e..82370c5a82c9 100644
--- a/libcxxabi/test/test_guard.pass.cpp
+++ b/libcxxabi/test/test_guard.pass.cpp
@@ -12,6 +12,7 @@
 
 #ifndef _LIBCXXABI_HAS_NO_THREADS
 #include <thread>
+#include "make_test_thread.h"
 #endif
 
 #include "test_macros.h"
@@ -97,7 +98,8 @@ namespace test4 {
     }
 
     void test() {
-        std::thread t1(helper), t2(helper);
+        std::thread t1 = support::make_test_thread(helper);
+        std::thread t2 = support::make_test_thread(helper);
         t1.join();
         t2.join();
         assert(run_count == 1);
@@ -124,12 +126,12 @@ namespace test5 {
 
     void helper() {
         static int a = one(); ((void)a);
-        std::thread t(another_helper);
+        std::thread t = support::make_test_thread(another_helper);
         t.join();
     }
 
     void test() {
-        std::thread t(helper);
+        std::thread t = support::make_test_thread(helper);
         t.join();
         assert(run_count == 1);
     }

diff  --git a/libcxxabi/test/thread_local_destruction_order.pass.cpp b/libcxxabi/test/thread_local_destruction_order.pass.cpp
index eeb90b820b87..a01f9848a277 100644
--- a/libcxxabi/test/thread_local_destruction_order.pass.cpp
+++ b/libcxxabi/test/thread_local_destruction_order.pass.cpp
@@ -25,6 +25,8 @@
 #include <cassert>
 #include <thread>
 
+#include "make_test_thread.h"
+
 int seq = 0;
 
 class OrderChecker {
@@ -59,7 +61,7 @@ void thread_fn() {
 int main(int, char**) {
   static OrderChecker fn_static{6};
 
-  std::thread{thread_fn}.join();
+  support::make_test_thread(thread_fn).join();
   assert(seq == 3);
 
   thread_local OrderChecker fn_thread_local{4};


        


More information about the libcxx-commits mailing list