Skip to content

Commit

Permalink
#1002 Add option do disable signal hanlders in vt::finalize
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobDomagala committed Sep 7, 2020
1 parent f9b7e74 commit 8ed61a6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
15 changes: 11 additions & 4 deletions src/vt/runtime/runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ bool Runtime::tryInitialize() {
return init_now;
}

bool Runtime::tryFinalize() {
bool Runtime::tryFinalize(bool const disable_sig) {
bool const rt_live = !finalized_ && initialized_;
bool const has_run_sched = hasSchedRun();
bool const finalize_now = rt_live && has_run_sched;
Expand All @@ -347,7 +347,7 @@ bool Runtime::tryFinalize() {
);

if (finalize_now) {
finalize(true);
finalize(true, disable_sig);
} else {
finalize_on_term_ = true;
}
Expand Down Expand Up @@ -399,7 +399,7 @@ bool Runtime::initialize(bool const force_now) {
}
}

bool Runtime::finalize(bool const force_now) {
bool Runtime::finalize(bool const force_now, bool const disable_sig) {
if (force_now) {
using component::BaseComponent;

Expand Down Expand Up @@ -431,10 +431,17 @@ bool Runtime::finalize(bool const force_now) {
}

finalizeMPI();

if (disable_sig) {
signal(SIGSEGV, SIG_DFL);
signal(SIGUSR1, SIG_DFL);
signal(SIGINT, SIG_DFL);
}

finalized_ = true;
return true;
} else {
return tryFinalize();
return tryFinalize(disable_sig);
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/vt/runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@ struct Runtime {
* \internal \brief Finalize the runtime
*
* \param[in] force_now whether to force finalization regardless of state
* \param[in] disable_sig whether to disable signal handlers
*
* \return whether it finalized or not
*/
bool finalize(bool const force_now = false);
bool finalize(bool const force_now = false, bool const disable_sig = true);

/**
* \brief Run the scheduler once
Expand Down Expand Up @@ -252,10 +253,11 @@ struct Runtime {

/**
* \internal \brief Try to finalize
* \param[in] disable_sig whether to disable signal handlers
*
* \return whether it succeeded
*/
bool tryFinalize();
bool tryFinalize(bool const disable_sig);

/**
* \internal \brief Setup argument input
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/pipe/test_signal_cleanup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ TEST_F(TestSignalCleanup, test_signal_cleanup_3) {
do vt::runScheduler(); while (not vt::rt->isTerminated());

// explicitly finalize runtime to destroy and reset components
vt::rt->finalize(true);
vt::rt->finalize(true, false);

// re-init runtime, fresh state---force it now!
vt::rt->initialize(true);
Expand Down

0 comments on commit 8ed61a6

Please sign in to comment.