diff --git a/include/exec/async_scope.hpp b/include/exec/async_scope.hpp index f125242d2..4e6cb0456 100644 --- a/include/exec/async_scope.hpp +++ b/include/exec/async_scope.hpp @@ -160,6 +160,7 @@ namespace exec { static void __complete(const __impl* __scope) noexcept { auto& __active = __scope->__active_; if (__active.fetch_sub(1, __std::memory_order_acq_rel) == 1) { + usleep(rand() % 1000); std::unique_lock __guard{__scope->__lock_}; auto __local_waiters = std::move(__scope->__waiters_); __guard.unlock(); diff --git a/test/exec/async_scope/test_spawn_future.cpp b/test/exec/async_scope/test_spawn_future.cpp index 8d592e979..40d0127b5 100644 --- a/test/exec/async_scope/test_spawn_future.cpp +++ b/test/exec/async_scope/test_spawn_future.cpp @@ -143,8 +143,12 @@ namespace { #if !STDEXEC_STD_NO_EXCEPTIONS() TEST_CASE("spawn_future with throwing copy", "[async_scope][spawn_future]") { - async_scope scope; - exec::static_thread_pool pool{2}; + while(1) { + std::optional pool; + std::shared_ptr scope; + + pool.emplace(2); + scope = std::make_shared(); struct throwing_copy { throwing_copy() = default; @@ -154,8 +158,8 @@ namespace { } }; - ex::sender auto snd = scope.spawn_future( - ex::starts_on(pool.get_scheduler(), exec::just_from([](auto sink) { + ex::sender auto snd = scope->spawn_future( + ex::starts_on(pool->get_scheduler(), exec::just_from([](auto sink) { return sink(throwing_copy()); }))); STDEXEC_TRY { @@ -168,8 +172,12 @@ namespace { STDEXEC_CATCH_ALL { FAIL("invalid exception caught"); } - sync_wait(scope.on_empty()); + sync_wait(scope->on_empty()); + + scope.reset(); + pool.reset(); } +} #endif // !STDEXEC_STD_NO_EXCEPTIONS() TEST_CASE(