diff --git a/include/condy/runtime.hpp b/include/condy/runtime.hpp index db20affd..645f7a3b 100644 --- a/include/condy/runtime.hpp +++ b/include/condy/runtime.hpp @@ -346,6 +346,11 @@ class Runtime { schedule_msg_ring_( curr_runtime, detail::encode_work(nullptr, detail::WorkType::Ignore)); + if (curr_runtime != nullptr) { + // Ensure the wakeup msg is submitted. Since user may call + // thread.join() after allow_exit() + curr_runtime->ring_.submit(); + } } void flush_global_queue_() noexcept { diff --git a/tests/test_runtime.cpp b/tests/test_runtime.cpp index 45a45cfb..db6f1538 100644 --- a/tests/test_runtime.cpp +++ b/tests/test_runtime.cpp @@ -5,6 +5,7 @@ #include "condy/runtime_options.hpp" #include "condy/task.hpp" #include +#include #include #include @@ -322,3 +323,21 @@ TEST_CASE("test runtime - runtime destroyed on another runtime") { runtime_a.allow_exit(); runtime_a.run(); } + +TEST_CASE("test runtime - runtime join on another runtime") { + condy::Runtime runtime_a(options); + + auto func = [&]() -> condy::Coro { + auto runtime_b = std::make_unique(options); + std::thread thread_b([&]() { runtime_b->run(); }); + // wait runtime_b call submit_and_wait + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + runtime_b->allow_exit(); + thread_b.join(); + co_return; + }; + + condy::co_spawn(runtime_a, func()).detach(); + runtime_a.allow_exit(); + runtime_a.run(); +} \ No newline at end of file