Skip to content
Open
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
14 changes: 12 additions & 2 deletions src/collective/loop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void Loop::Process() {
}
}

Result Loop::Stop() {
Result Loop::Stop(bool from_destructor) {
// Finish all remaining tasks
CHECK_EQ(this->Block().OK(), this->rc_.OK());

Expand All @@ -214,7 +214,17 @@ Result Loop::Stop() {
}

if (curr_exce_) {
std::rethrow_exception(curr_exce_);
if (from_destructor) {
try {
std::rethrow_exception(curr_exce_);
} catch (const std::exception& e) {
return Fail("Exception in loop: " + std::string(e.what()));
} catch (...) {
return Fail("Unknown exception in loop");
}
} else {
std::rethrow_exception(curr_exce_);
}
}

return Success();
Expand Down
7 changes: 4 additions & 3 deletions src/collective/loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Loop {
/**
* @brief Stop the worker thread.
*/
Result Stop();
Result Stop(bool from_destructor = false);

void Submit(Op op);

Expand All @@ -84,9 +84,10 @@ class Loop {

explicit Loop(std::chrono::seconds timeout);

~Loop() noexcept(false) {
~Loop() noexcept {
// The worker will be joined in the stop function.
this->Stop();
this->Stop(true);
}

};
} // namespace xgboost::collective