diff --git a/test/async.cpp b/test/async.cpp index 08c688657..541a4cd87 100644 --- a/test/async.cpp +++ b/test/async.cpp @@ -16,7 +16,6 @@ #include #include -#include #include #include @@ -182,11 +181,11 @@ BOOST_AUTO_TEST_CASE(async_wait_different_contexts, *boost::unit_test::timeout(1 BOOST_REQUIRE(!ec); // Regression test for #143: make sure each io_context handles its own children - std::thread thr1{[&]{io_context1.run();}}; - std::thread thr2{[&]{io_context2.run();}}; + std::future thread1 = std::async(std::launch::async, [&]{io_context1.run();}); + std::future thread2 = std::async(std::launch::async, [&]{io_context2.run();}); - thr1.join(); - thr2.join(); + thread1.get(); + thread2.get(); c1.wait(ec); BOOST_REQUIRE(!ec); @@ -404,12 +403,12 @@ BOOST_AUTO_TEST_CASE(mixed_async, *boost::unit_test::timeout(5)) ); BOOST_REQUIRE(!ec); - std::thread thr([&]{c.wait();}); + std::future thread = std::async(std::launch::async, [&]{c.wait();}); io_context.run(); BOOST_CHECK(exit_called); BOOST_CHECK_EQUAL(c.exit_code(), 42); - thr.join(); + thread.get(); }*/ diff --git a/test/async_pipe.cpp b/test/async_pipe.cpp index ef6cab4be..ac45fca50 100644 --- a/test/async_pipe.cpp +++ b/test/async_pipe.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -70,21 +71,19 @@ BOOST_AUTO_TEST_CASE(closed_transform) BOOST_AUTO_TEST_CASE(multithreaded_async_pipe) { asio::io_context ioc; - - std::vector threads; + std::vector> threads; for (int i = 0; i < std::thread::hardware_concurrency(); i++) { - threads.emplace_back([&ioc] + threads.emplace_back(std::async(std::launch::async, [&ioc] { - std::vector pipes; + std::vector> pipes; for (size_t i = 0; i < 100; i++) - pipes.push_back(new bp::async_pipe(ioc)); - for (auto &p : pipes) - delete p; - }); + pipes.emplace_back(std::make_unique(ioc)); + })); + } + for (auto &future : threads) { + future.get(); } - for (auto &t : threads) - t.join(); } diff --git a/test/group_wait.cpp b/test/group_wait.cpp index 5f6c55730..d7cfb9c88 100644 --- a/test/group_wait.cpp +++ b/test/group_wait.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -34,13 +35,14 @@ namespace bp = boost::process; BOOST_AUTO_TEST_CASE(wait_group_test, *boost::unit_test::timeout(5)) { std::atomic done{false}; - std::thread thr{ + std::future thread = std::async(std::launch::async, [&] { for (int i = 0; i < 50 && !done.load(); i++) std::this_thread::sleep_for(std::chrono::milliseconds(100)); BOOST_REQUIRE(done.load()); - }}; + } + ); using boost::unit_test::framework::master_test_suite; @@ -77,7 +79,7 @@ BOOST_AUTO_TEST_CASE(wait_group_test, *boost::unit_test::timeout(5)) BOOST_CHECK(!c2.running()); done.store(true); - thr.join(); + thread.get(); } @@ -86,13 +88,14 @@ BOOST_AUTO_TEST_CASE(wait_group_test_timeout, *boost::unit_test::timeout(15)) using boost::unit_test::framework::master_test_suite; std::atomic done{false}; - std::thread thr{ + std::future thread = std::async(std::launch::async, [&] { for (int i = 0; i < 150 && !done.load(); i++) std::this_thread::sleep_for(std::chrono::milliseconds(100)); BOOST_REQUIRE(done.load()); - }}; + } + ); std::error_code ec; bp::group g; @@ -131,5 +134,5 @@ BOOST_AUTO_TEST_CASE(wait_group_test_timeout, *boost::unit_test::timeout(15)) BOOST_CHECK(!c2.running()); done.store(true); - thr.join(); + thread.get(); } \ No newline at end of file diff --git a/test/on_exit3.cpp b/test/on_exit3.cpp index 84fe6845c..13efe8f20 100644 --- a/test/on_exit3.cpp +++ b/test/on_exit3.cpp @@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE(double_ios_threaded, *boost::unit_test::timeout(6)) { p2 = std::chrono::steady_clock::now(); })); // wait for the notifications - std::thread ([&ios] { ios.run(); }).join(); + ios.run(); BOOST_REQUIRE((p2 - p1) > std::chrono::seconds(1)); } diff --git a/test/pipe.cpp b/test/pipe.cpp index cb0caf8dc..a7e578619 100644 --- a/test/pipe.cpp +++ b/test/pipe.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include @@ -246,11 +246,11 @@ BOOST_AUTO_TEST_CASE(large_data, *boost::unit_test::timeout(20)) for (auto & c: in) c = (cnt++ % 26) + 'A'; - std::thread th([&]{os << in << std::endl;}); + std::future thread = std::async(std::launch::async, [&]{os << in << std::endl;}); is >> out; BOOST_REQUIRE_EQUAL_COLLECTIONS(out.begin(), out.end(), in.begin(), in.end()); - th.join(); + thread.get(); } BOOST_AUTO_TEST_CASE(closed, *boost::unit_test::timeout(2)) diff --git a/test/terminate.cpp b/test/terminate.cpp index 0e9ce722b..566520bd0 100644 --- a/test/terminate.cpp +++ b/test/terminate.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -25,13 +26,14 @@ namespace bp = boost::process; BOOST_AUTO_TEST_CASE(terminate_set_on_error, *boost::unit_test::timeout(5)) { std::atomic done{false}; - std::thread thr{ + std::future thread = std::async(std::launch::async, [&] { for (int i = 0; i < 50 && !done.load(); i++) std::this_thread::sleep_for(std::chrono::milliseconds(100)); BOOST_REQUIRE(done.load()); - }}; + } + ); using boost::unit_test::framework::master_test_suite; std::error_code ec; @@ -55,19 +57,20 @@ BOOST_AUTO_TEST_CASE(terminate_set_on_error, *boost::unit_test::timeout(5)) BOOST_CHECK(!ec); done.store(true); - thr.join(); + thread.get(); } BOOST_AUTO_TEST_CASE(terminate_throw_on_error, *boost::unit_test::timeout(5)) { std::atomic done{false}; - std::thread thr{ + std::future thread = std::async(std::launch::async, [&] { for (int i = 0; i < 50 && !done.load(); i++) std::this_thread::sleep_for(std::chrono::milliseconds(100)); BOOST_REQUIRE(done.load()); - }}; + } + ); using boost::unit_test::framework::master_test_suite; @@ -91,5 +94,5 @@ BOOST_AUTO_TEST_CASE(terminate_throw_on_error, *boost::unit_test::timeout(5)) BOOST_CHECK(!c.running()); done.store(true); - thr.join(); + thread.get(); }