forked from OSchip/llvm-project
[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:
parent
8e0148dff7
commit
564628014c
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
Loading…
Reference in New Issue