[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.
This commit is contained in:
Louis Dionne 2020-11-23 15:52:03 -05:00
parent 8e0148dff7
commit 564628014c
103 changed files with 318 additions and 269 deletions

View File

@ -20,6 +20,7 @@
#include <thread> #include <thread>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
typedef std::shared_ptr<int> Ptr; typedef std::shared_ptr<int> Ptr;
@ -51,7 +52,7 @@ void run_test(Ptr p) {
assert(p.use_count() == 2); assert(p.use_count() == 2);
TestRunner r(p); TestRunner r(p);
assert(p.use_count() == 3); 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); assert(p.use_count() == 4);
Start = true; Start = true;
// Run until we witness 25 use count changes via both // Run until we witness 25 use count changes via both

View File

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

View File

@ -19,6 +19,7 @@
#include <future> #include <future>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
void func(std::promise<int> p) void func(std::promise<int> p)
@ -32,7 +33,7 @@ int main(int, char**)
typedef int T; typedef int T;
std::promise<T> p; std::promise<T> p;
std::future<T> f = p.get_future(); std::future<T> f = p.get_future();
std::thread(func, std::move(p)).detach(); support::make_test_thread(func, std::move(p)).detach();
try try
{ {
f.get(); f.get();

View File

@ -19,6 +19,7 @@
#include <memory> #include <memory>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
int i = 0; int i = 0;
@ -34,7 +35,7 @@ int main(int, char**)
{ {
std::promise<int&> p; std::promise<int&> p;
std::future<int&> f = p.get_future(); 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); assert(f.get() == 4);
} }

View File

@ -18,6 +18,7 @@
#include <memory> #include <memory>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
void func(std::promise<std::unique_ptr<int>> p) 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::promise<std::unique_ptr<int>> p;
std::future<std::unique_ptr<int>> f = p.get_future(); 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); assert(*f.get() == 5);
} }

View File

@ -18,6 +18,7 @@
#include <future> #include <future>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
void func(std::promise<int> p) void func(std::promise<int> p)
@ -31,7 +32,7 @@ int main(int, char**)
{ {
std::promise<int> p; std::promise<int> p;
std::future<int> f = p.get_future(); 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); assert(f.get() == 5);
} }

View File

@ -19,6 +19,7 @@
#include <memory> #include <memory>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
int i = 0; int i = 0;
@ -34,7 +35,7 @@ int main(int, char**)
{ {
std::promise<void> p; std::promise<void> p;
std::future<void> f = p.get_future(); 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(); f.get();
assert(i == 1); assert(i == 1);
} }

View File

@ -20,6 +20,7 @@
#include <future> #include <future>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
void func1(std::promise<int> p) void func1(std::promise<int> p)
@ -68,7 +69,7 @@ int main(int, char**)
{ {
std::promise<T> p; std::promise<T> p;
std::shared_future<T> f = p.get_future(); 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.valid());
assert(f.get() == 3); assert(f.get() == 3);
assert(f.valid()); assert(f.valid());
@ -77,7 +78,7 @@ int main(int, char**)
{ {
std::promise<T> p; std::promise<T> p;
std::shared_future<T> f = p.get_future(); 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 try
{ {
assert(f.valid()); assert(f.valid());
@ -97,7 +98,7 @@ int main(int, char**)
{ {
std::promise<T> p; std::promise<T> p;
std::shared_future<T> f = p.get_future(); 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.valid());
assert(f.get() == 5); assert(f.get() == 5);
assert(f.valid()); assert(f.valid());
@ -106,7 +107,7 @@ int main(int, char**)
{ {
std::promise<T> p; std::promise<T> p;
std::shared_future<T> f = p.get_future(); 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 try
{ {
assert(f.valid()); assert(f.valid());
@ -126,7 +127,7 @@ int main(int, char**)
{ {
std::promise<T> p; std::promise<T> p;
std::shared_future<T> f = p.get_future(); 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.valid());
f.get(); f.get();
assert(f.valid()); assert(f.valid());
@ -135,7 +136,7 @@ int main(int, char**)
{ {
std::promise<T> p; std::promise<T> p;
std::shared_future<T> f = p.get_future(); 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 try
{ {
assert(f.valid()); assert(f.valid());

View File

@ -18,6 +18,7 @@
#include <future> #include <future>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
void func1(std::promise<int> p) void func1(std::promise<int> p)
@ -49,7 +50,7 @@ int main(int, char**)
typedef int T; typedef int T;
std::promise<T> p; std::promise<T> p;
std::shared_future<T> f = p.get_future(); 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.valid());
f.wait(); f.wait();
assert(f.valid()); assert(f.valid());
@ -63,7 +64,7 @@ int main(int, char**)
typedef int& T; typedef int& T;
std::promise<T> p; std::promise<T> p;
std::shared_future<T> f = p.get_future(); 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.valid());
f.wait(); f.wait();
assert(f.valid()); assert(f.valid());
@ -77,7 +78,7 @@ int main(int, char**)
typedef void T; typedef void T;
std::promise<T> p; std::promise<T> p;
std::shared_future<T> f = p.get_future(); 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.valid());
f.wait(); f.wait();
assert(f.valid()); assert(f.valid());

View File

@ -20,6 +20,7 @@
#include <future> #include <future>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
typedef std::chrono::milliseconds ms; typedef std::chrono::milliseconds ms;
@ -56,7 +57,7 @@ int main(int, char**)
typedef int T; typedef int T;
std::promise<T> p; std::promise<T> p;
std::shared_future<T> f = p.get_future(); 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.valid());
assert(f.wait_for(ms(1)) == std::future_status::timeout); assert(f.wait_for(ms(1)) == std::future_status::timeout);
assert(f.valid()); assert(f.valid());
@ -69,7 +70,7 @@ int main(int, char**)
typedef int& T; typedef int& T;
std::promise<T> p; std::promise<T> p;
std::shared_future<T> f = p.get_future(); 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.valid());
assert(f.wait_for(ms(1)) == std::future_status::timeout); assert(f.wait_for(ms(1)) == std::future_status::timeout);
assert(f.valid()); assert(f.valid());
@ -82,7 +83,7 @@ int main(int, char**)
typedef void T; typedef void T;
std::promise<T> p; std::promise<T> p;
std::shared_future<T> f = p.get_future(); 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.valid());
assert(f.wait_for(ms(1)) == std::future_status::timeout); assert(f.wait_for(ms(1)) == std::future_status::timeout);
assert(f.valid()); assert(f.valid());
@ -97,7 +98,7 @@ int main(int, char**)
std::promise<T> p; std::promise<T> p;
std::shared_future<T> f = p.get_future(); std::shared_future<T> f = p.get_future();
Clock::time_point t0 = Clock::now(); 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.valid());
assert(f.wait_for(ms(1)) == std::future_status::timeout); assert(f.wait_for(ms(1)) == std::future_status::timeout);
assert(f.valid()); assert(f.valid());
@ -113,7 +114,7 @@ int main(int, char**)
std::promise<T> p; std::promise<T> p;
std::shared_future<T> f = p.get_future(); std::shared_future<T> f = p.get_future();
Clock::time_point t0 = Clock::now(); 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.valid());
assert(f.wait_for(ms(1)) == std::future_status::timeout); assert(f.wait_for(ms(1)) == std::future_status::timeout);
assert(f.valid()); assert(f.valid());
@ -129,7 +130,7 @@ int main(int, char**)
std::promise<T> p; std::promise<T> p;
std::shared_future<T> f = p.get_future(); std::shared_future<T> f = p.get_future();
Clock::time_point t0 = Clock::now(); 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.valid());
assert(f.wait_for(ms(1)) == std::future_status::timeout); assert(f.wait_for(ms(1)) == std::future_status::timeout);
assert(f.valid()); assert(f.valid());

View File

@ -21,6 +21,7 @@
#include <atomic> #include <atomic>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
enum class WorkerThreadState { Uninitialized, AllowedToRun, Exiting }; enum class WorkerThreadState { Uninitialized, AllowedToRun, Exiting };
@ -71,7 +72,7 @@ int main(int, char**)
typedef int T; typedef int T;
std::promise<T> p; std::promise<T> p;
std::shared_future<T> f = p.get_future(); 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.valid());
assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout); assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout);
assert(f.valid()); assert(f.valid());
@ -89,7 +90,7 @@ int main(int, char**)
typedef int& T; typedef int& T;
std::promise<T> p; std::promise<T> p;
std::shared_future<T> f = p.get_future(); 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.valid());
assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout); assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout);
assert(f.valid()); assert(f.valid());
@ -107,7 +108,7 @@ int main(int, char**)
typedef void T; typedef void T;
std::promise<T> p; std::promise<T> p;
std::shared_future<T> f = p.get_future(); 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.valid());
assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout); assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout);
assert(f.valid()); assert(f.valid());

View File

@ -18,6 +18,7 @@
#include <future> #include <future>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
class A class A
@ -45,7 +46,7 @@ int main(int, char**)
{ {
std::packaged_task<double(int, char)> p(A(5)); std::packaged_task<double(int, char)> p(A(5));
std::future<double> f = p.get_future(); std::future<double> f = p.get_future();
std::thread(func, std::move(p)).detach(); support::make_test_thread(func, std::move(p)).detach();
try try
{ {
double i = f.get(); double i = f.get();
@ -61,7 +62,7 @@ int main(int, char**)
{ {
std::packaged_task<double(int, char)> p(A(5)); std::packaged_task<double(int, char)> p(A(5));
std::future<double> f = p.get_future(); 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); assert(f.get() == 105.0);
} }

View File

@ -18,6 +18,7 @@
#include <future> #include <future>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
class A class A
@ -85,14 +86,14 @@ int main(int, char**)
{ {
std::packaged_task<double(int, char)> p(A(5)); std::packaged_task<double(int, char)> p(A(5));
std::future<double> f = p.get_future(); 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); assert(f.get() == 105.0);
} }
#ifndef TEST_HAS_NO_EXCEPTIONS #ifndef TEST_HAS_NO_EXCEPTIONS
{ {
std::packaged_task<double(int, char)> p(A(5)); std::packaged_task<double(int, char)> p(A(5));
std::future<double> f = p.get_future(); std::future<double> f = p.get_future();
std::thread(func1, std::move(p)).detach(); support::make_test_thread(func1, std::move(p)).detach();
try try
{ {
f.get(); f.get();
@ -106,12 +107,12 @@ int main(int, char**)
{ {
std::packaged_task<double(int, char)> p(A(5)); std::packaged_task<double(int, char)> p(A(5));
std::future<double> f = p.get_future(); 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); assert(f.get() == 105.0);
} }
{ {
std::packaged_task<double(int, char)> p; 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(); t.join();
} }
#endif #endif

View File

@ -18,6 +18,7 @@
#include <future> #include <future>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
class A class A
@ -85,14 +86,14 @@ int main(int, char**)
{ {
std::packaged_task<double(int, char)> p(A(5)); std::packaged_task<double(int, char)> p(A(5));
std::future<double> f = p.get_future(); 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); assert(f.get() == 105.0);
} }
#ifndef TEST_HAS_NO_EXCEPTIONS #ifndef TEST_HAS_NO_EXCEPTIONS
{ {
std::packaged_task<double(int, char)> p(A(5)); std::packaged_task<double(int, char)> p(A(5));
std::future<double> f = p.get_future(); std::future<double> f = p.get_future();
std::thread(func1, std::move(p)).detach(); support::make_test_thread(func1, std::move(p)).detach();
try try
{ {
f.get(); f.get();
@ -106,13 +107,13 @@ int main(int, char**)
{ {
std::packaged_task<double(int, char)> p(A(5)); std::packaged_task<double(int, char)> p(A(5));
std::future<double> f = p.get_future(); 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); assert(f.get() == 105.0);
t.join(); t.join();
} }
{ {
std::packaged_task<double(int, char)> p; 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(); t.join();
} }
#endif #endif

View File

@ -20,6 +20,7 @@
#include <future> #include <future>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
void func1(std::promise<int> p) void func1(std::promise<int> p)
@ -68,7 +69,7 @@ int main(int, char**)
{ {
std::promise<T> p; std::promise<T> p;
std::future<T> f = p.get_future(); 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.valid());
assert(f.get() == 3); assert(f.get() == 3);
assert(!f.valid()); assert(!f.valid());
@ -77,7 +78,7 @@ int main(int, char**)
{ {
std::promise<T> p; std::promise<T> p;
std::future<T> f = p.get_future(); std::future<T> f = p.get_future();
std::thread(func2, std::move(p)).detach(); support::make_test_thread(func2, std::move(p)).detach();
try try
{ {
assert(f.valid()); assert(f.valid());
@ -97,7 +98,7 @@ int main(int, char**)
{ {
std::promise<T> p; std::promise<T> p;
std::future<T> f = p.get_future(); 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.valid());
assert(f.get() == 5); assert(f.get() == 5);
assert(!f.valid()); assert(!f.valid());
@ -106,7 +107,7 @@ int main(int, char**)
{ {
std::promise<T> p; std::promise<T> p;
std::future<T> f = p.get_future(); std::future<T> f = p.get_future();
std::thread(func4, std::move(p)).detach(); support::make_test_thread(func4, std::move(p)).detach();
try try
{ {
assert(f.valid()); assert(f.valid());
@ -126,7 +127,7 @@ int main(int, char**)
{ {
std::promise<T> p; std::promise<T> p;
std::future<T> f = p.get_future(); 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.valid());
f.get(); f.get();
assert(!f.valid()); assert(!f.valid());
@ -135,7 +136,7 @@ int main(int, char**)
{ {
std::promise<T> p; std::promise<T> p;
std::future<T> f = p.get_future(); std::future<T> f = p.get_future();
std::thread(func6, std::move(p)).detach(); support::make_test_thread(func6, std::move(p)).detach();
try try
{ {
assert(f.valid()); assert(f.valid());

View File

@ -18,6 +18,7 @@
#include <future> #include <future>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
void func1(std::promise<int> p) void func1(std::promise<int> p)
@ -48,7 +49,7 @@ void test(F func) {
std::promise<T> p; std::promise<T> p;
std::future<T> f = p.get_future(); 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()); assert(f.valid());
f.wait(); f.wait();
assert(f.valid()); assert(f.valid());

View File

@ -20,6 +20,7 @@
#include <future> #include <future>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
typedef std::chrono::milliseconds ms; typedef std::chrono::milliseconds ms;
@ -54,7 +55,7 @@ void test(F func, bool waitFirst) {
std::promise<T> p; std::promise<T> p;
std::future<T> f = p.get_future(); std::future<T> f = p.get_future();
Clock::time_point t1, t0 = Clock::now(); 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.valid());
assert(f.wait_for(ms(1)) == std::future_status::timeout); assert(f.wait_for(ms(1)) == std::future_status::timeout);
assert(f.valid()); assert(f.valid());

View File

@ -21,6 +21,7 @@
#include <atomic> #include <atomic>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
enum class WorkerThreadState { Uninitialized, AllowedToRun, Exiting }; enum class WorkerThreadState { Uninitialized, AllowedToRun, Exiting };
@ -70,7 +71,7 @@ int main(int, char**)
typedef int T; typedef int T;
std::promise<T> p; std::promise<T> p;
std::future<T> f = p.get_future(); 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.valid());
assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout); assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout);
assert(f.valid()); assert(f.valid());
@ -88,7 +89,7 @@ int main(int, char**)
typedef int& T; typedef int& T;
std::promise<T> p; std::promise<T> p;
std::future<T> f = p.get_future(); 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.valid());
assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout); assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout);
assert(f.valid()); assert(f.valid());
@ -106,7 +107,7 @@ int main(int, char**)
typedef void T; typedef void T;
std::promise<T> p; std::promise<T> p;
std::future<T> f = p.get_future(); 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.valid());
assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout); assert(f.wait_until(Clock::now() + ms(10)) == std::future_status::timeout);
assert(f.valid()); assert(f.valid());

View File

@ -25,6 +25,7 @@
#include <barrier> #include <barrier>
#include <thread> #include <thread>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
int main(int, char**) int main(int, char**)
@ -32,7 +33,7 @@ int main(int, char**)
std::barrier<> b(2); std::barrier<> b(2);
auto tok = b.arrive(); auto tok = b.arrive();
std::thread t([&](){ std::thread t = support::make_test_thread([&](){
(void)b.arrive(); (void)b.arrive();
}); });
b.wait(std::move(tok)); b.wait(std::move(tok));

View File

@ -26,13 +26,14 @@
#include <thread> #include <thread>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
int main(int, char**) int main(int, char**)
{ {
std::barrier<> b(2); std::barrier<> b(2);
std::thread t([&](){ std::thread t = support::make_test_thread([&](){
b.arrive_and_drop(); b.arrive_and_drop();
}); });

View File

@ -25,13 +25,14 @@
#include <barrier> #include <barrier>
#include <thread> #include <thread>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
int main(int, char**) int main(int, char**)
{ {
std::barrier<> b(2); std::barrier<> b(2);
std::thread t([&](){ std::thread t = support::make_test_thread([&](){
for(int i = 0; i < 10; ++i) for(int i = 0; i < 10; ++i)
b.arrive_and_wait(); b.arrive_and_wait();
}); });

View File

@ -26,6 +26,7 @@
#include <thread> #include <thread>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
int main(int, char**) int main(int, char**)
@ -34,7 +35,7 @@ int main(int, char**)
auto comp = [&]() { x += 1; }; auto comp = [&]() { x += 1; };
std::barrier<decltype(comp)> b(2, comp); std::barrier<decltype(comp)> b(2, comp);
std::thread t([&](){ std::thread t = support::make_test_thread([&](){
for(int i = 0; i < 10; ++i) for(int i = 0; i < 10; ++i)
b.arrive_and_wait(); b.arrive_and_wait();
}); });

View File

@ -23,6 +23,7 @@
#include <chrono> #include <chrono>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::condition_variable cv; std::condition_variable cv;
@ -41,7 +42,7 @@ void func()
int main(int, char**) int main(int, char**)
{ {
std::unique_lock<std::mutex> lk(mut); 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(); Clock::time_point t0 = Clock::now();
cv.wait(lk); cv.wait(lk);
Clock::time_point t1 = Clock::now(); Clock::time_point t1 = Clock::now();

View File

@ -19,6 +19,7 @@
#include <thread> #include <thread>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::condition_variable* cv; std::condition_variable* cv;
@ -48,12 +49,12 @@ void g()
int main(int, char**) int main(int, char**)
{ {
cv = new std::condition_variable; cv = new std::condition_variable;
std::thread th2(g); std::thread th2 = support::make_test_thread(g);
Lock lk(m); Lock lk(m);
while (!g_ready) while (!g_ready)
cv->wait(lk); cv->wait(lk);
lk.unlock(); lk.unlock();
std::thread th1(f); std::thread th1 = support::make_test_thread(f);
th1.join(); th1.join();
th2.join(); th2.join();

View File

@ -19,6 +19,7 @@
#include <thread> #include <thread>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::condition_variable cv; std::condition_variable cv;
@ -50,8 +51,8 @@ void f2()
int main(int, char**) int main(int, char**)
{ {
std::thread t1(f1); std::thread t1 = support::make_test_thread(f1);
std::thread t2(f2); std::thread t2 = support::make_test_thread(f2);
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(std::chrono::milliseconds(100));
{ {
std::unique_lock<std::mutex>lk(mut); std::unique_lock<std::mutex>lk(mut);

View File

@ -41,6 +41,7 @@
#include <thread> #include <thread>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
@ -78,8 +79,8 @@ void f2()
int main(int, char**) int main(int, char**)
{ {
std::thread t1(f1); std::thread t1 = support::make_test_thread(f1);
std::thread t2(f2); std::thread t2 = support::make_test_thread(f2);
{ {
while (ready > 0) while (ready > 0)
std::this_thread::yield(); std::this_thread::yield();

View File

@ -19,6 +19,7 @@
#include <thread> #include <thread>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::condition_variable cv; std::condition_variable cv;
@ -40,8 +41,8 @@ void f()
int main(int, char**) int main(int, char**)
{ {
std::unique_lock<std::mutex>lk(mut); std::unique_lock<std::mutex> lk(mut);
std::thread t(f); std::thread t = support::make_test_thread(f);
assert(test1 == 0); assert(test1 == 0);
while (test1 == 0) while (test1 == 0)
cv.wait(lk); cv.wait(lk);

View File

@ -25,6 +25,7 @@
#include <chrono> #include <chrono>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::condition_variable cv; std::condition_variable cv;
@ -64,8 +65,8 @@ void f()
int main(int, char**) int main(int, char**)
{ {
{ {
std::unique_lock<std::mutex>lk(mut); std::unique_lock<std::mutex> lk(mut);
std::thread t(f); std::thread t = support::make_test_thread(f);
assert(test1 == 0); assert(test1 == 0);
while (test1 == 0) while (test1 == 0)
cv.wait(lk); cv.wait(lk);
@ -78,8 +79,8 @@ int main(int, char**)
test1 = 0; test1 = 0;
test2 = 0; test2 = 0;
{ {
std::unique_lock<std::mutex>lk(mut); std::unique_lock<std::mutex> lk(mut);
std::thread t(f); std::thread t = support::make_test_thread(f);
assert(test1 == 0); assert(test1 == 0);
while (test1 == 0) while (test1 == 0)
cv.wait(lk); cv.wait(lk);

View File

@ -24,6 +24,7 @@
#include <chrono> #include <chrono>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
class Pred class Pred
@ -72,7 +73,7 @@ int main(int, char**)
{ {
{ {
std::unique_lock<std::mutex>lk(mut); std::unique_lock<std::mutex>lk(mut);
std::thread t(f); std::thread t = support::make_test_thread(f);
assert(test1 == 0); assert(test1 == 0);
while (test1 == 0) while (test1 == 0)
cv.wait(lk); cv.wait(lk);
@ -86,7 +87,7 @@ int main(int, char**)
test2 = 0; test2 = 0;
{ {
std::unique_lock<std::mutex>lk(mut); std::unique_lock<std::mutex>lk(mut);
std::thread t(f); std::thread t = support::make_test_thread(f);
assert(test1 == 0); assert(test1 == 0);
while (test1 == 0) while (test1 == 0)
cv.wait(lk); cv.wait(lk);

View File

@ -21,6 +21,7 @@
#include <functional> #include <functional>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::condition_variable cv; std::condition_variable cv;
@ -51,7 +52,7 @@ void f()
int main(int, char**) int main(int, char**)
{ {
std::unique_lock<std::mutex>lk(mut); std::unique_lock<std::mutex>lk(mut);
std::thread t(f); std::thread t = support::make_test_thread(f);
assert(test1 == 0); assert(test1 == 0);
while (test1 == 0) while (test1 == 0)
cv.wait(lk); cv.wait(lk);

View File

@ -23,6 +23,7 @@
#include <chrono> #include <chrono>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
struct TestClock struct TestClock
@ -83,7 +84,7 @@ void run_test()
test2 = 0; test2 = 0;
{ {
std::unique_lock<std::mutex>lk(mut); std::unique_lock<std::mutex>lk(mut);
std::thread t(f<Clock>); std::thread t = support::make_test_thread(f<Clock>);
assert(test1 == 0); assert(test1 == 0);
while (test1 == 0) while (test1 == 0)
cv.wait(lk); cv.wait(lk);
@ -97,7 +98,7 @@ void run_test()
test2 = 0; test2 = 0;
{ {
std::unique_lock<std::mutex>lk(mut); std::unique_lock<std::mutex>lk(mut);
std::thread t(f<Clock>); std::thread t = support::make_test_thread(f<Clock>);
assert(test1 == 0); assert(test1 == 0);
while (test1 == 0) while (test1 == 0)
cv.wait(lk); cv.wait(lk);

View File

@ -26,6 +26,7 @@
#include <chrono> #include <chrono>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
struct Clock struct Clock
@ -90,8 +91,8 @@ void f()
int main(int, char**) int main(int, char**)
{ {
{ {
std::unique_lock<std::mutex>lk(mut); std::unique_lock<std::mutex> lk(mut);
std::thread t(f); std::thread t = support::make_test_thread(f);
assert(test1 == 0); assert(test1 == 0);
while (test1 == 0) while (test1 == 0)
cv.wait(lk); cv.wait(lk);
@ -104,8 +105,8 @@ int main(int, char**)
test1 = 0; test1 = 0;
test2 = 0; test2 = 0;
{ {
std::unique_lock<std::mutex>lk(mut); std::unique_lock<std::mutex> lk(mut);
std::thread t(f); std::thread t = support::make_test_thread(f);
assert(test1 == 0); assert(test1 == 0);
while (test1 == 0) while (test1 == 0)
cv.wait(lk); cv.wait(lk);

View File

@ -19,6 +19,7 @@
#include <thread> #include <thread>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::condition_variable_any* cv; std::condition_variable_any* cv;
@ -49,12 +50,12 @@ void g()
int main(int, char**) int main(int, char**)
{ {
cv = new std::condition_variable_any; cv = new std::condition_variable_any;
std::thread th2(g); std::thread th2 = support::make_test_thread(g);
m.lock(); m.lock();
while (!g_ready) while (!g_ready)
cv->wait(m); cv->wait(m);
m.unlock(); m.unlock();
std::thread th1(f); std::thread th1 = support::make_test_thread(f);
th1.join(); th1.join();
th2.join(); th2.join();

View File

@ -21,6 +21,7 @@
#include <atomic> #include <atomic>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::condition_variable_any cv; std::condition_variable_any cv;
@ -46,7 +47,7 @@ int main(int, char**)
notReady = threadCount; notReady = threadCount;
std::vector<std::thread> threads(threadCount); std::vector<std::thread> threads(threadCount);
for (unsigned i = 0; i < threadCount; i++) for (unsigned i = 0; i < threadCount; i++)
threads[i] = std::thread(helper); threads[i] = support::make_test_thread(helper);
{ {
while (notReady > 0) while (notReady > 0)
std::this_thread::yield(); std::this_thread::yield();

View File

@ -21,6 +21,7 @@
#include <thread> #include <thread>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::condition_variable_any cv; std::condition_variable_any cv;
@ -56,8 +57,8 @@ void f2()
int main(int, char**) int main(int, char**)
{ {
std::thread t1(f1); std::thread t1 = support::make_test_thread(f1);
std::thread t2(f2); std::thread t2 = support::make_test_thread(f2);
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(std::chrono::milliseconds(100));
{ {
L1 lk(m0); L1 lk(m0);

View File

@ -20,6 +20,7 @@
#include <thread> #include <thread>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::condition_variable_any cv; std::condition_variable_any cv;
@ -46,7 +47,7 @@ void f()
int main(int, char**) int main(int, char**)
{ {
L1 lk(m0); L1 lk(m0);
std::thread t(f); std::thread t = support::make_test_thread(f);
assert(test1 == 0); assert(test1 == 0);
while (test1 == 0) while (test1 == 0)
cv.wait(lk); cv.wait(lk);

View File

@ -24,6 +24,7 @@
#include <chrono> #include <chrono>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::condition_variable_any cv; std::condition_variable_any cv;
@ -68,7 +69,7 @@ int main(int, char**)
{ {
{ {
L1 lk(m0); L1 lk(m0);
std::thread t(f); std::thread t = support::make_test_thread(f);
assert(test1 == 0); assert(test1 == 0);
while (test1 == 0) while (test1 == 0)
cv.wait(lk); cv.wait(lk);
@ -82,7 +83,7 @@ int main(int, char**)
test2 = 0; test2 = 0;
{ {
L1 lk(m0); L1 lk(m0);
std::thread t(f); std::thread t = support::make_test_thread(f);
assert(test1 == 0); assert(test1 == 0);
while (test1 == 0) while (test1 == 0)
cv.wait(lk); cv.wait(lk);

View File

@ -23,6 +23,7 @@
#include <chrono> #include <chrono>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
class Pred class Pred
@ -77,7 +78,7 @@ int main(int, char**)
{ {
expect_result = true; expect_result = true;
L1 lk(m0); L1 lk(m0);
std::thread t(f); std::thread t = support::make_test_thread(f);
assert(test1 == 0); assert(test1 == 0);
while (test1 == 0) while (test1 == 0)
cv.wait(lk); cv.wait(lk);
@ -92,7 +93,7 @@ int main(int, char**)
{ {
expect_result = false; expect_result = false;
L1 lk(m0); L1 lk(m0);
std::thread t(f); std::thread t = support::make_test_thread(f);
assert(test1 == 0); assert(test1 == 0);
while (test1 == 0) while (test1 == 0)
cv.wait(lk); cv.wait(lk);

View File

@ -21,6 +21,7 @@
#include <functional> #include <functional>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::condition_variable_any cv; std::condition_variable_any cv;
@ -55,7 +56,7 @@ void f()
int main(int, char**) int main(int, char**)
{ {
L1 lk(m0); L1 lk(m0);
std::thread t(f); std::thread t = support::make_test_thread(f);
assert(test1 == 0); assert(test1 == 0);
while (test1 == 0) while (test1 == 0)
cv.wait(lk); cv.wait(lk);

View File

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

View File

@ -22,6 +22,7 @@
#include <chrono> #include <chrono>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
struct Clock struct Clock
@ -81,7 +82,7 @@ int main(int, char**)
{ {
{ {
L1 lk(m0); L1 lk(m0);
std::thread t(f); std::thread t = support::make_test_thread(f);
assert(test1 == 0); assert(test1 == 0);
while (test1 == 0) while (test1 == 0)
cv.wait(lk); cv.wait(lk);
@ -95,7 +96,7 @@ int main(int, char**)
test2 = 0; test2 = 0;
{ {
L1 lk(m0); L1 lk(m0);
std::thread t(f); std::thread t = support::make_test_thread(f);
assert(test1 == 0); assert(test1 == 0);
while (test1 == 0) while (test1 == 0)
cv.wait(lk); cv.wait(lk);

View File

@ -26,6 +26,7 @@
#include <chrono> #include <chrono>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
struct Clock struct Clock
@ -95,7 +96,7 @@ int main(int, char**)
{ {
{ {
L1 lk(m0); L1 lk(m0);
std::thread t(f); std::thread t = support::make_test_thread(f);
assert(test1 == 0); assert(test1 == 0);
while (test1 == 0) while (test1 == 0)
cv.wait(lk); cv.wait(lk);
@ -109,7 +110,7 @@ int main(int, char**)
test2 = 0; test2 = 0;
{ {
L1 lk(m0); L1 lk(m0);
std::thread t(f); std::thread t = support::make_test_thread(f);
assert(test1 == 0); assert(test1 == 0);
while (test1 == 0) while (test1 == 0)
cv.wait(lk); cv.wait(lk);

View File

@ -25,13 +25,14 @@
#include <latch> #include <latch>
#include <thread> #include <thread>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
int main(int, char**) int main(int, char**)
{ {
std::latch l(2); std::latch l(2);
std::thread t([&](){ std::thread t = support::make_test_thread([&](){
l.arrive_and_wait(); l.arrive_and_wait();
}); });
l.arrive_and_wait(); l.arrive_and_wait();

View File

@ -25,6 +25,7 @@
#include <latch> #include <latch>
#include <thread> #include <thread>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
int main(int, char**) int main(int, char**)
@ -32,7 +33,7 @@ int main(int, char**)
std::latch l(2); std::latch l(2);
l.count_down(); l.count_down();
std::thread t([&](){ std::thread t = support::make_test_thread([&](){
l.count_down(); l.count_down();
}); });
l.wait(); l.wait();

View File

@ -31,6 +31,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
typedef std::chrono::system_clock Clock; typedef std::chrono::system_clock Clock;
@ -82,7 +83,7 @@ int main(int, char**)
{ {
m.lock(); m.lock();
for (int i = 0; i < 5; ++i) 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); std::this_thread::sleep_for(WaitTime);
m.unlock(); m.unlock();
for (auto& t : v) for (auto& t : v)
@ -91,8 +92,8 @@ int main(int, char**)
{ {
m.lock_shared(); m.lock_shared();
for (auto& t : v) for (auto& t : v)
t = std::thread(g); t = support::make_test_thread(g);
std::thread q(f); std::thread q = support::make_test_thread(f);
std::this_thread::sleep_for(WaitTime); std::this_thread::sleep_for(WaitTime);
m.unlock_shared(); m.unlock_shared();
for (auto& t : v) for (auto& t : v)

View File

@ -27,6 +27,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::shared_timed_mutex m; std::shared_timed_mutex m;
@ -75,7 +76,7 @@ int main(int, char**)
m.lock(); m.lock();
std::vector<std::thread> v; std::vector<std::thread> v;
for (unsigned i = 0; i < Threads; ++i) for (unsigned i = 0; i < Threads; ++i)
v.push_back(std::thread(f1)); v.push_back(support::make_test_thread(f1));
while (CountDown > 0) while (CountDown > 0)
std::this_thread::yield(); std::this_thread::yield();
// Give one more chance for threads to block and wait for the mutex. // Give one more chance for threads to block and wait for the mutex.
@ -89,7 +90,7 @@ int main(int, char**)
m.lock(); m.lock();
std::vector<std::thread> v; std::vector<std::thread> v;
for (unsigned i = 0; i < Threads; ++i) 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) for (auto& t : v)
t.join(); t.join();
m.unlock(); m.unlock();

View File

@ -27,6 +27,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::shared_timed_mutex m; std::shared_timed_mutex m;
@ -69,7 +70,7 @@ int main(int, char**)
m.lock(); m.lock();
std::vector<std::thread> v; std::vector<std::thread> v;
for (unsigned i = 0; i < Threads; ++i) for (unsigned i = 0; i < Threads; ++i)
v.push_back(std::thread(f1)); v.push_back(support::make_test_thread(f1));
while (CountDown > 0) while (CountDown > 0)
std::this_thread::yield(); std::this_thread::yield();
std::this_thread::sleep_for(ShortTime); std::this_thread::sleep_for(ShortTime);
@ -81,7 +82,7 @@ int main(int, char**)
m.lock(); m.lock();
std::vector<std::thread> v; std::vector<std::thread> v;
for (unsigned i = 0; i < Threads; ++i) 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) for (auto& t : v)
t.join(); t.join();
m.unlock(); m.unlock();

View File

@ -28,6 +28,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::shared_timed_mutex m; std::shared_timed_mutex m;
@ -69,7 +70,7 @@ int main(int, char**)
m.lock(); m.lock();
std::vector<std::thread> v; std::vector<std::thread> v;
for (int i = 0; i < 5; ++i) 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)); std::this_thread::sleep_for(ms(250));
m.unlock(); m.unlock();
for (auto& t : v) for (auto& t : v)

View File

@ -28,6 +28,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::shared_timed_mutex m; std::shared_timed_mutex m;
@ -90,7 +91,7 @@ int main(int, char**)
m.lock(); m.lock();
std::vector<std::thread> v; std::vector<std::thread> v;
for (int i = 0; i < 5; ++i) 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); std::this_thread::sleep_for(WaitTime);
m.unlock(); m.unlock();
for (auto& t : v) for (auto& t : v)

View File

@ -24,6 +24,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::mutex m; std::mutex m;
@ -49,7 +50,7 @@ void f()
int main(int, char**) int main(int, char**)
{ {
m.lock(); m.lock();
std::thread t(f); std::thread t = support::make_test_thread(f);
std::this_thread::sleep_for(ms(250)); std::this_thread::sleep_for(ms(250));
m.unlock(); m.unlock();
t.join(); t.join();

View File

@ -22,6 +22,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::timed_mutex m; std::timed_mutex m;
@ -56,14 +57,14 @@ int main(int, char**)
{ {
{ {
m.lock(); m.lock();
std::thread t(f1); std::thread t = support::make_test_thread(f1);
std::this_thread::sleep_for(ms(250)); std::this_thread::sleep_for(ms(250));
m.unlock(); m.unlock();
t.join(); t.join();
} }
{ {
m.lock(); m.lock();
std::thread t(f2); std::thread t = support::make_test_thread(f2);
std::this_thread::sleep_for(ms(300)); std::this_thread::sleep_for(ms(300));
m.unlock(); m.unlock();
t.join(); t.join();

View File

@ -22,6 +22,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::timed_mutex m; std::timed_mutex m;
@ -56,14 +57,14 @@ int main(int, char**)
{ {
{ {
m.lock(); m.lock();
std::thread t(f1); std::thread t = support::make_test_thread(f1);
std::this_thread::sleep_for(ms(250)); std::this_thread::sleep_for(ms(250));
m.unlock(); m.unlock();
t.join(); t.join();
} }
{ {
m.lock(); m.lock();
std::thread t(f2); std::thread t = support::make_test_thread(f2);
std::this_thread::sleep_for(ms(300)); std::this_thread::sleep_for(ms(300));
m.unlock(); m.unlock();
t.join(); t.join();

View File

@ -20,6 +20,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::mutex m; std::mutex m;
@ -59,7 +60,7 @@ void f()
int main(int, char**) int main(int, char**)
{ {
m.lock(); m.lock();
std::thread t(f); std::thread t = support::make_test_thread(f);
std::this_thread::sleep_for(ms(250)); std::this_thread::sleep_for(ms(250));
m.unlock(); m.unlock();
t.join(); t.join();

View File

@ -21,6 +21,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::mutex m; std::mutex m;
@ -69,7 +70,7 @@ void f()
int main(int, char**) int main(int, char**)
{ {
m.lock(); m.lock();
std::thread t(f); std::thread t = support::make_test_thread(f);
std::this_thread::sleep_for(ms(250)); std::this_thread::sleep_for(ms(250));
m.unlock(); m.unlock();
t.join(); t.join();

View File

@ -21,6 +21,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::mutex m; std::mutex m;
@ -44,7 +45,7 @@ void f()
int main(int, char**) int main(int, char**)
{ {
m.lock(); m.lock();
std::thread t(f); std::thread t = support::make_test_thread(f);
std::this_thread::sleep_for(ms(250)); std::this_thread::sleep_for(ms(250));
m.unlock(); m.unlock();
t.join(); t.join();

View File

@ -21,6 +21,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::mutex m; std::mutex m;
@ -48,7 +49,7 @@ void f()
int main(int, char**) int main(int, char**)
{ {
m.lock(); m.lock();
std::thread t(f); std::thread t = support::make_test_thread(f);
std::this_thread::sleep_for(ms(250)); std::this_thread::sleep_for(ms(250));
m.unlock(); m.unlock();
t.join(); t.join();

View File

@ -20,6 +20,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::recursive_mutex m; std::recursive_mutex m;
@ -45,7 +46,7 @@ void f()
int main(int, char**) int main(int, char**)
{ {
m.lock(); m.lock();
std::thread t(f); std::thread t = support::make_test_thread(f);
std::this_thread::sleep_for(ms(250)); std::this_thread::sleep_for(ms(250));
m.unlock(); m.unlock();
t.join(); t.join();

View File

@ -21,6 +21,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::recursive_mutex m; std::recursive_mutex m;
@ -50,7 +51,7 @@ void f()
int main(int, char**) int main(int, char**)
{ {
m.lock(); m.lock();
std::thread t(f); std::thread t = support::make_test_thread(f);
std::this_thread::sleep_for(ms(250)); std::this_thread::sleep_for(ms(250));
m.unlock(); m.unlock();
t.join(); t.join();

View File

@ -27,6 +27,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::shared_mutex m; std::shared_mutex m;
@ -61,7 +62,7 @@ void f()
int main(int, char**) int main(int, char**)
{ {
m.lock(); m.lock();
std::thread t(f); std::thread t = support::make_test_thread(f);
std::this_thread::sleep_for(WaitTime); std::this_thread::sleep_for(WaitTime);
m.unlock(); m.unlock();
t.join(); t.join();

View File

@ -28,6 +28,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::shared_mutex m; std::shared_mutex m;
@ -75,15 +76,15 @@ int main(int, char**)
m.lock(); m.lock();
std::vector<std::thread> v; std::vector<std::thread> v;
for (int i = 0; i < 5; ++i) 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); std::this_thread::sleep_for(WaitTime);
m.unlock(); m.unlock();
for (auto& t : v) for (auto& t : v)
t.join(); t.join();
m.lock_shared(); m.lock_shared();
for (auto& t : v) for (auto& t : v)
t = std::thread(g); t = support::make_test_thread(g);
std::thread q(f); std::thread q = support::make_test_thread(f);
std::this_thread::sleep_for(WaitTime); std::this_thread::sleep_for(WaitTime);
m.unlock_shared(); m.unlock_shared();
for (auto& t : v) for (auto& t : v)

View File

@ -27,6 +27,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::shared_mutex m; std::shared_mutex m;
@ -54,7 +55,7 @@ void f()
int main(int, char**) int main(int, char**)
{ {
m.lock(); m.lock();
std::thread t(f); std::thread t = support::make_test_thread(f);
std::this_thread::sleep_for(ms(250)); std::this_thread::sleep_for(ms(250));
m.unlock(); m.unlock();
t.join(); t.join();

View File

@ -28,6 +28,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::shared_mutex m; std::shared_mutex m;
@ -58,7 +59,7 @@ int main(int, char**)
m.lock(); m.lock();
std::vector<std::thread> v; std::vector<std::thread> v;
for (int i = 0; i < 5; ++i) 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)); std::this_thread::sleep_for(ms(250));
m.unlock(); m.unlock();
for (auto& t : v) for (auto& t : v)

View File

@ -25,6 +25,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::shared_timed_mutex m; std::shared_timed_mutex m;
@ -54,7 +55,7 @@ void f()
int main(int, char**) int main(int, char**)
{ {
m.lock(); m.lock();
std::thread t(f); std::thread t = support::make_test_thread(f);
while (!ready) while (!ready)
std::this_thread::yield(); std::this_thread::yield();
start = Clock::now(); start = Clock::now();

View File

@ -26,6 +26,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::shared_timed_mutex m; std::shared_timed_mutex m;
@ -76,7 +77,7 @@ int main(int, char**)
m.lock(); m.lock();
std::vector<std::thread> v; std::vector<std::thread> v;
for (int i = 0; i < threads; ++i) for (int i = 0; i < threads; ++i)
v.push_back(std::thread(readerMustWait)); v.push_back(support::make_test_thread(readerMustWait));
while (countDown > 0) while (countDown > 0)
std::this_thread::yield(); std::this_thread::yield();
readerStart = Clock::now(); readerStart = Clock::now();
@ -88,8 +89,8 @@ int main(int, char**)
countDown.store(threads + 1); countDown.store(threads + 1);
m.lock_shared(); m.lock_shared();
for (auto& t : v) for (auto& t : v)
t = std::thread(reader); t = support::make_test_thread(reader);
std::thread q(writerMustWait); std::thread q = support::make_test_thread(writerMustWait);
while (countDown > 0) while (countDown > 0)
std::this_thread::yield(); std::this_thread::yield();
writerStart = Clock::now(); writerStart = Clock::now();

View File

@ -27,6 +27,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::shared_timed_mutex m; std::shared_timed_mutex m;
@ -54,7 +55,7 @@ void f()
int main(int, char**) int main(int, char**)
{ {
m.lock(); m.lock();
std::thread t(f); std::thread t = support::make_test_thread(f);
std::this_thread::sleep_for(ms(250)); std::this_thread::sleep_for(ms(250));
m.unlock(); m.unlock();
t.join(); t.join();

View File

@ -28,6 +28,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::shared_timed_mutex m; std::shared_timed_mutex m;
@ -73,14 +74,14 @@ int main(int, char**)
{ {
{ {
m.lock(); m.lock();
std::thread t(f1); std::thread t = support::make_test_thread(f1);
std::this_thread::sleep_for(WaitTime); std::this_thread::sleep_for(WaitTime);
m.unlock(); m.unlock();
t.join(); t.join();
} }
{ {
m.lock(); m.lock();
std::thread t(f2); std::thread t = support::make_test_thread(f2);
std::this_thread::sleep_for(WaitTime + Tolerance); std::this_thread::sleep_for(WaitTime + Tolerance);
m.unlock(); m.unlock();
t.join(); t.join();

View File

@ -28,6 +28,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::shared_timed_mutex m; std::shared_timed_mutex m;
@ -64,7 +65,7 @@ int main(int, char**)
m.lock(); m.lock();
std::vector<std::thread> v; std::vector<std::thread> v;
for (int i = 0; i < 5; ++i) 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)); std::this_thread::sleep_for(ms(250));
m.unlock(); m.unlock();
for (auto& t : v) for (auto& t : v)

View File

@ -29,6 +29,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::shared_timed_mutex m; std::shared_timed_mutex m;
@ -75,7 +76,7 @@ int main(int, char**)
m.lock(); m.lock();
std::vector<std::thread> v; std::vector<std::thread> v;
for (int i = 0; i < 5; ++i) 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); std::this_thread::sleep_for(WaitTime);
m.unlock(); m.unlock();
for (auto& t : v) for (auto& t : v)
@ -85,7 +86,7 @@ int main(int, char**)
m.lock(); m.lock();
std::vector<std::thread> v; std::vector<std::thread> v;
for (int i = 0; i < 5; ++i) 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); std::this_thread::sleep_for(WaitTime + Tolerance);
m.unlock(); m.unlock();
for (auto& t : v) for (auto& t : v)

View File

@ -29,6 +29,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::shared_timed_mutex m; std::shared_timed_mutex m;
@ -72,7 +73,7 @@ int main(int, char**)
m.lock(); m.lock();
std::vector<std::thread> v; std::vector<std::thread> v;
for (int i = 0; i < threads; ++i) for (int i = 0; i < threads; ++i)
v.push_back(std::thread(f1)); v.push_back(support::make_test_thread(f1));
while (countDown > 0) while (countDown > 0)
std::this_thread::yield(); std::this_thread::yield();
m.unlock(); m.unlock();
@ -83,7 +84,7 @@ int main(int, char**)
m.lock(); m.lock();
std::vector<std::thread> v; std::vector<std::thread> v;
for (int i = 0; i < threads; ++i) 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) for (auto& t : v)
t.join(); t.join();
m.unlock(); m.unlock();

View File

@ -28,6 +28,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::shared_timed_mutex m; std::shared_timed_mutex m;
@ -73,14 +74,14 @@ int main(int, char**)
{ {
{ {
m.lock(); m.lock();
std::thread t(f1); std::thread t = support::make_test_thread(f1);
std::this_thread::sleep_for(WaitTime); std::this_thread::sleep_for(WaitTime);
m.unlock(); m.unlock();
t.join(); t.join();
} }
{ {
m.lock(); m.lock();
std::thread t(f2); std::thread t = support::make_test_thread(f2);
std::this_thread::sleep_for(WaitTime + Tolerance); std::this_thread::sleep_for(WaitTime + Tolerance);
m.unlock(); m.unlock();
t.join(); t.join();

View File

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

View File

@ -20,6 +20,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::timed_mutex m; std::timed_mutex m;
@ -43,7 +44,7 @@ void f()
int main(int, char**) int main(int, char**)
{ {
m.lock(); m.lock();
std::thread t(f); std::thread t = support::make_test_thread(f);
std::this_thread::sleep_for(ms(250)); std::this_thread::sleep_for(ms(250));
m.unlock(); m.unlock();
t.join(); t.join();

View File

@ -20,6 +20,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::timed_mutex m; std::timed_mutex m;
@ -47,7 +48,7 @@ void f()
int main(int, char**) int main(int, char**)
{ {
m.lock(); m.lock();
std::thread t(f); std::thread t = support::make_test_thread(f);
std::this_thread::sleep_for(ms(250)); std::this_thread::sleep_for(ms(250));
m.unlock(); m.unlock();
t.join(); t.join();

View File

@ -21,6 +21,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::timed_mutex m; std::timed_mutex m;
@ -54,14 +55,14 @@ int main(int, char**)
{ {
{ {
m.lock(); m.lock();
std::thread t(f1); std::thread t = support::make_test_thread(f1);
std::this_thread::sleep_for(ms(250)); std::this_thread::sleep_for(ms(250));
m.unlock(); m.unlock();
t.join(); t.join();
} }
{ {
m.lock(); m.lock();
std::thread t(f2); std::thread t = support::make_test_thread(f2);
std::this_thread::sleep_for(ms(300)); std::this_thread::sleep_for(ms(300));
m.unlock(); m.unlock();
t.join(); t.join();

View File

@ -21,6 +21,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::timed_mutex m; std::timed_mutex m;
@ -54,14 +55,14 @@ int main(int, char**)
{ {
{ {
m.lock(); m.lock();
std::thread t(f1); std::thread t = support::make_test_thread(f1);
std::this_thread::sleep_for(ms(250)); std::this_thread::sleep_for(ms(250));
m.unlock(); m.unlock();
t.join(); t.join();
} }
{ {
m.lock(); m.lock();
std::thread t(f2); std::thread t = support::make_test_thread(f2);
std::this_thread::sleep_for(ms(300)); std::this_thread::sleep_for(ms(300));
m.unlock(); m.unlock();
t.join(); t.join();

View File

@ -20,6 +20,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::recursive_timed_mutex m; std::recursive_timed_mutex m;
@ -45,7 +46,7 @@ void f()
int main(int, char**) int main(int, char**)
{ {
m.lock(); m.lock();
std::thread t(f); std::thread t = support::make_test_thread(f);
std::this_thread::sleep_for(ms(250)); std::this_thread::sleep_for(ms(250));
m.unlock(); m.unlock();
t.join(); t.join();

View File

@ -20,6 +20,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::recursive_timed_mutex m; std::recursive_timed_mutex m;
@ -49,7 +50,7 @@ void f()
int main(int, char**) int main(int, char**)
{ {
m.lock(); m.lock();
std::thread t(f); std::thread t = support::make_test_thread(f);
std::this_thread::sleep_for(ms(250)); std::this_thread::sleep_for(ms(250));
m.unlock(); m.unlock();
t.join(); t.join();

View File

@ -21,6 +21,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::recursive_timed_mutex m; std::recursive_timed_mutex m;
@ -56,14 +57,14 @@ int main(int, char**)
{ {
{ {
m.lock(); m.lock();
std::thread t(f1); std::thread t = support::make_test_thread(f1);
std::this_thread::sleep_for(ms(250)); std::this_thread::sleep_for(ms(250));
m.unlock(); m.unlock();
t.join(); t.join();
} }
{ {
m.lock(); m.lock();
std::thread t(f2); std::thread t = support::make_test_thread(f2);
std::this_thread::sleep_for(ms(300)); std::this_thread::sleep_for(ms(300));
m.unlock(); m.unlock();
t.join(); t.join();

View File

@ -21,6 +21,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::recursive_timed_mutex m; std::recursive_timed_mutex m;
@ -56,14 +57,14 @@ int main(int, char**)
{ {
{ {
m.lock(); m.lock();
std::thread t(f1); std::thread t = support::make_test_thread(f1);
std::this_thread::sleep_for(ms(250)); std::this_thread::sleep_for(ms(250));
m.unlock(); m.unlock();
t.join(); t.join();
} }
{ {
m.lock(); m.lock();
std::thread t(f2); std::thread t = support::make_test_thread(f2);
std::this_thread::sleep_for(ms(300)); std::this_thread::sleep_for(ms(300));
m.unlock(); m.unlock();
t.join(); t.join();

View File

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

View File

@ -23,6 +23,7 @@
#include <thread> #include <thread>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::once_flag flg0; std::once_flag flg0;
@ -41,8 +42,8 @@ void f0()
int main(int, char**) int main(int, char**)
{ {
std::thread t0(f0); std::thread t0 = support::make_test_thread(f0);
std::thread t1(f0); std::thread t1 = support::make_test_thread(f0);
t0.join(); t0.join();
t1.join(); t1.join();
assert(global == 1); assert(global == 1);

View File

@ -25,13 +25,14 @@
#include <semaphore> #include <semaphore>
#include <thread> #include <thread>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
int main(int, char**) int main(int, char**)
{ {
std::counting_semaphore<> s(2); std::counting_semaphore<> s(2);
std::thread t([&](){ std::thread t = support::make_test_thread([&](){
s.acquire(); s.acquire();
}); });
t.join(); t.join();

View File

@ -26,6 +26,7 @@
#include <chrono> #include <chrono>
#include <thread> #include <thread>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
int main(int, char**) 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(); l();
t.join(); t.join();

View File

@ -25,6 +25,7 @@
#include <semaphore> #include <semaphore>
#include <thread> #include <thread>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
int main(int, char**) int main(int, char**)
@ -34,7 +35,7 @@ int main(int, char**)
s.release(); s.release();
s.acquire(); s.acquire();
std::thread t([&](){ std::thread t = support::make_test_thread([&](){
s.acquire(); s.acquire();
}); });
s.release(2); s.release(2);

View File

@ -26,6 +26,7 @@
#include <thread> #include <thread>
#include <chrono> #include <chrono>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
int main(int, char**) 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_until(start + std::chrono::milliseconds(250)));
assert(!s.try_acquire_for(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)); std::this_thread::sleep_for(std::chrono::milliseconds(250));
s.release(); s.release();
std::this_thread::sleep_for(std::chrono::milliseconds(250)); std::this_thread::sleep_for(std::chrono::milliseconds(250));

View File

@ -25,6 +25,7 @@
#include <semaphore> #include <semaphore>
#include <thread> #include <thread>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
int main(int, char**) int main(int, char**)
@ -35,7 +36,7 @@ int main(int, char**)
s.release(); s.release();
assert(s.try_acquire()); assert(s.try_acquire());
s.release(2); s.release(2);
std::thread t([&](){ std::thread t = support::make_test_thread([&](){
assert(s.try_acquire()); assert(s.try_acquire());
}); });
t.join(); t.join();

View File

@ -19,6 +19,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
class G class G
@ -47,7 +48,7 @@ int main(int, char**)
{ {
{ {
G g; G g;
std::thread t0(g); std::thread t0 = support::make_test_thread(g);
std::thread::id id0 = t0.get_id(); std::thread::id id0 = t0.get_id();
std::thread t1; std::thread t1;
std::thread::id id1 = t1.get_id(); std::thread::id id1 = t1.get_id();

View File

@ -13,40 +13,11 @@
// thread& operator=(thread&& t); // thread& operator=(thread&& t);
#include <thread> #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**) int main(int, char**)
{ {
{ std::thread t0;
std::thread t0(G()); std::thread t1;
std::thread t1; t0 = t1;
t1 = t0; return 0;
}
return 0;
} }

View File

@ -18,6 +18,7 @@
#include <cassert> #include <cassert>
#include <utility> #include <utility>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
class G class G
@ -51,7 +52,7 @@ int main(int, char**)
assert(G::n_alive == 1); assert(G::n_alive == 1);
assert(!G::op_run); 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::id id = t0.get_id();
std::thread t1; std::thread t1;

View File

@ -20,6 +20,7 @@
#include <exception> #include <exception>
#include <utility> #include <utility>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
struct G struct G
@ -37,7 +38,7 @@ int main(int, char**)
std::set_terminate(f1); std::set_terminate(f1);
{ {
G g; G g;
std::thread t0(g); std::thread t0 = support::make_test_thread(g);
std::thread t1; std::thread t1;
t0 = std::move(t1); t0 = std::move(t1);
assert(false); assert(false);

View File

@ -16,12 +16,10 @@
#include <thread> #include <thread>
#include <cassert>
int main(int, char**) int main(int, char**)
{ {
volatile std::thread t1; volatile std::thread t1;
std::thread t2 ( t1, 1, 2.0 ); std::thread t2 ( t1, 1, 2.0 );
return 0;
return 0;
} }

View File

@ -13,55 +13,10 @@
// thread(const thread&) = delete; // thread(const thread&) = delete;
#include <thread> #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**) int main(int, char**)
{ {
{ std::thread t0; (void)t0;
assert(G::n_alive == 0); std::thread t1(t0); (void)t1;
assert(!G::op_run); return 0;
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;
} }

View File

@ -19,6 +19,7 @@
#include <cstdlib> #include <cstdlib>
#include <utility> #include <utility>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
class G class G
@ -52,7 +53,7 @@ int main(int, char**)
assert(G::n_alive == 1); assert(G::n_alive == 1);
assert(!G::op_run); 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::id id = t0.get_id();
std::thread t1 = std::move(t0); std::thread t1 = std::move(t0);

View File

@ -20,6 +20,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
class G class G
@ -57,7 +58,7 @@ int main(int, char**)
assert(!G::op_run); assert(!G::op_run);
G g; G g;
{ {
std::thread t(g); std::thread t = support::make_test_thread(g);
std::this_thread::sleep_for(std::chrono::milliseconds(250)); std::this_thread::sleep_for(std::chrono::milliseconds(250));
} }
} }

View File

@ -19,6 +19,7 @@
#include <system_error> #include <system_error>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
std::atomic_bool done(false); std::atomic_bool done(false);
@ -65,7 +66,7 @@ int main(int, char**)
{ {
{ {
G g; G g;
std::thread t0(g); std::thread t0 = support::make_test_thread(g);
assert(t0.joinable()); assert(t0.joinable());
t0.detach(); t0.detach();
assert(!t0.joinable()); assert(!t0.joinable());
@ -76,7 +77,7 @@ int main(int, char**)
assert(G::n_alive == 0); assert(G::n_alive == 0);
#ifndef TEST_HAS_NO_EXCEPTIONS #ifndef TEST_HAS_NO_EXCEPTIONS
{ {
std::thread t0(foo); std::thread t0 = support::make_test_thread(foo);
assert(t0.joinable()); assert(t0.joinable());
t0.detach(); t0.detach();
assert(!t0.joinable()); assert(!t0.joinable());

View File

@ -19,6 +19,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
class G class G
@ -47,7 +48,7 @@ int main(int, char**)
{ {
{ {
G g; G g;
std::thread t0(g); std::thread t0 = support::make_test_thread(g);
std::thread::id id0 = t0.get_id(); std::thread::id id0 = t0.get_id();
std::thread t1; std::thread t1;
std::thread::id id1 = t1.get_id(); std::thread::id id1 = t1.get_id();

View File

@ -20,6 +20,7 @@
#include <cassert> #include <cassert>
#include <system_error> #include <system_error>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
class G class G
@ -50,7 +51,7 @@ int main(int, char**)
{ {
{ {
G g; G g;
std::thread t0(g); std::thread t0 = support::make_test_thread(g);
assert(t0.joinable()); assert(t0.joinable());
t0.join(); t0.join();
assert(!t0.joinable()); assert(!t0.joinable());
@ -64,7 +65,7 @@ int main(int, char**)
} }
#ifndef TEST_HAS_NO_EXCEPTIONS #ifndef TEST_HAS_NO_EXCEPTIONS
{ {
std::thread t0(foo); std::thread t0 = support::make_test_thread(foo);
t0.detach(); t0.detach();
try { try {
t0.join(); t0.join();

View File

@ -19,6 +19,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
class G class G
@ -47,7 +48,7 @@ int main(int, char**)
{ {
{ {
G g; G g;
std::thread t0(g); std::thread t0 = support::make_test_thread(g);
assert(t0.joinable()); assert(t0.joinable());
t0.join(); t0.join();
assert(!t0.joinable()); assert(!t0.joinable());

View File

@ -19,6 +19,7 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "make_test_thread.h"
#include "test_macros.h" #include "test_macros.h"
class G class G
@ -47,7 +48,7 @@ int main(int, char**)
{ {
{ {
G g; G g;
std::thread t0(g); std::thread t0 = support::make_test_thread(g);
std::thread::id id0 = t0.get_id(); std::thread::id id0 = t0.get_id();
std::thread t1; std::thread t1;
std::thread::id id1 = t1.get_id(); std::thread::id id1 = t1.get_id();

View File

@ -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

Some files were not shown because too many files have changed in this diff Show More