[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.

GitOrigin-RevId: 564628014c404bf57aa7cd9a5337198046bdd1ed
diff --git a/test/guard_threaded_test.pass.cpp b/test/guard_threaded_test.pass.cpp
index 7e5e0de..798d11b 100644
--- a/test/guard_threaded_test.pass.cpp
+++ b/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 @@
   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/test/test_guard.pass.cpp b/test/test_guard.pass.cpp
index 2168986..82370c5 100644
--- a/test/test_guard.pass.cpp
+++ b/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 @@
     }
 
     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 @@
 
     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/test/thread_local_destruction_order.pass.cpp b/test/thread_local_destruction_order.pass.cpp
index eeb90b8..a01f984 100644
--- a/test/thread_local_destruction_order.pass.cpp
+++ b/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 @@
 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};