Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/condy/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions tests/test_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "condy/runtime_options.hpp"
#include "condy/task.hpp"
#include <atomic>
#include <chrono>
#include <doctest.h>
#include <thread>

Expand Down Expand Up @@ -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<void> {
auto runtime_b = std::make_unique<condy::Runtime>(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();
}
Loading