Skip to content

Commit

Permalink
tsan test fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
klemens-morgenstern committed Oct 19, 2023
1 parent 19f8487 commit 210dce3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
25 changes: 15 additions & 10 deletions test/main.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
// Copyright (c) 2022 Klemens D. Morgenstern
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <boost/cobalt.hpp>
#include <boost/cobalt/main.hpp>
#include <boost/asio/steady_timer.hpp>

namespace cobalt = boost::cobalt;

boost::cobalt::main co_main(int argc, char *argv[])
auto cobalt_task() -> cobalt::task<int>
{
boost::asio::steady_timer tim{co_await boost::asio::this_coro::executor, std::chrono::milliseconds(50)};
co_await tim.async_wait(boost::cobalt::use_op);

co_return 0;
}


cobalt::main co_main(int argc, char * argv[])
{
constexpr std::size_t nb = 10000000;

for (std::size_t i = 0;i <nb; ++i)
{

co_await cobalt_task();
}
co_return 0;
}
4 changes: 0 additions & 4 deletions test/strand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ cobalt::promise<void> do_the_thing()

asio::steady_timer tim{co_await cobalt::this_coro::executor, std::chrono::milliseconds(50)};
co_await tim.async_wait(cobalt::use_op);


unique++;
BOOST_CHECK(unique == 1);
unique--;
Expand Down Expand Up @@ -61,8 +59,6 @@ BOOST_AUTO_TEST_CASE(strand)

for (auto & th : ths)
th.join();


}

BOOST_AUTO_TEST_SUITE_END();
Expand Down
20 changes: 10 additions & 10 deletions test/task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ CO_TEST_CASE(reawait)

cobalt::task<int> test_strand1(asio::any_io_executor exec)
{
BOOST_REQUIRE(exec == co_await cobalt::this_coro::executor);
BOOST_ASSERT(exec == co_await cobalt::this_coro::executor);
co_await asio::post(co_await cobalt::this_coro::executor, cobalt::use_task);
co_return 31;
}
Expand All @@ -282,15 +282,15 @@ BOOST_AUTO_TEST_CASE(stranded)

asio::thread_pool ctx;
boost::cobalt::this_thread::set_executor(ctx.get_executor());
cobalt::spawn(asio::make_strand(ctx.get_executor()), test_strand(),[](std::exception_ptr ep) { BOOST_CHECK(!ep); });
cobalt::spawn(asio::make_strand(ctx.get_executor()), test_strand(),[](std::exception_ptr ep) { BOOST_CHECK(!ep); });
cobalt::spawn(asio::make_strand(ctx.get_executor()), test_strand(),[](std::exception_ptr ep) { BOOST_CHECK(!ep); });
cobalt::spawn(asio::make_strand(ctx.get_executor()), test_strand(),[](std::exception_ptr ep) { BOOST_CHECK(!ep); });
cobalt::spawn(asio::make_strand(ctx.get_executor()), test_strand(),[](std::exception_ptr ep) { BOOST_CHECK(!ep); });
cobalt::spawn(asio::make_strand(ctx.get_executor()), test_strand(),[](std::exception_ptr ep) { BOOST_CHECK(!ep); });
cobalt::spawn(asio::make_strand(ctx.get_executor()), test_strand(),[](std::exception_ptr ep) { BOOST_CHECK(!ep); });
cobalt::spawn(asio::make_strand(ctx.get_executor()), test_strand(),[](std::exception_ptr ep) { BOOST_CHECK(!ep); });
ctx.join();
cobalt::spawn(asio::make_strand(ctx.get_executor()), test_strand(),[](std::exception_ptr ep) { if (ep) std::rethrow_exception(ep); });
cobalt::spawn(asio::make_strand(ctx.get_executor()), test_strand(),[](std::exception_ptr ep) { if (ep) std::rethrow_exception(ep); });
cobalt::spawn(asio::make_strand(ctx.get_executor()), test_strand(),[](std::exception_ptr ep) { if (ep) std::rethrow_exception(ep); });
cobalt::spawn(asio::make_strand(ctx.get_executor()), test_strand(),[](std::exception_ptr ep) { if (ep) std::rethrow_exception(ep); });
cobalt::spawn(asio::make_strand(ctx.get_executor()), test_strand(),[](std::exception_ptr ep) { if (ep) std::rethrow_exception(ep); });
cobalt::spawn(asio::make_strand(ctx.get_executor()), test_strand(),[](std::exception_ptr ep) { if (ep) std::rethrow_exception(ep); });
cobalt::spawn(asio::make_strand(ctx.get_executor()), test_strand(),[](std::exception_ptr ep) { if (ep) std::rethrow_exception(ep); });
cobalt::spawn(asio::make_strand(ctx.get_executor()), test_strand(),[](std::exception_ptr ep) { if (ep) std::rethrow_exception(ep); });
BOOST_CHECK_NO_THROW(ctx.join());
}

#endif
Expand Down
2 changes: 1 addition & 1 deletion test/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ boost::cobalt::thread thr_stop()
#if !defined(BOOST_COBALT_USE_IO_CONTEXT)
auto exec = co_await boost::asio::this_coro::executor;
auto &exc = *exec.target<boost::asio::io_context::executor_type>();
BOOST_REQUIRE(&exc != nullptr);
BOOST_ASSERT(&exc != nullptr);
#else
auto exc = co_await boost::asio::this_coro::executor;
#endif
Expand Down

0 comments on commit 210dce3

Please sign in to comment.