Skip to content
Snippets Groups Projects
Commit eeb0e063 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Fix error/signal handling raised in a multi-threaded context

parent 6b4eb157
No related branches found
No related tags found
1 merge request!205High-order polynomial reconstruction
......@@ -52,17 +52,27 @@ SignalManager::signalName(int signal)
void
SignalManager::pauseForDebug(int signal)
{
if (std::string(PUGS_BUILD_TYPE) != "Release") {
if (s_pause_on_error) {
// Each failing process must write
std::cerr.clear();
if (std::string(PUGS_BUILD_TYPE) != "Release") {
char hostname[HOST_NAME_MAX + 1];
gethostname(hostname, HOST_NAME_MAX + 1);
std::cerr << "\n======================================\n"
<< rang::style::reset << rang::fg::reset << rang::style::bold << "to attach gdb to this process run\n"
<< rang::style::reset << rang::fg::reset << rang::style::bold << "Process paused on host \""
<< rang::fg::yellow << hostname << rang::fg::reset << "\"\n"
<< "to attach gdb to this process run\n"
<< "\tgdb -pid " << rang::fg::red << getpid() << rang::fg::reset << '\n'
<< "else press Control-C to exit\n"
<< rang::style::reset << "======================================\n"
<< std::flush;
pause();
} else {
std::cerr << '\n'
<< rang::style::bold
<< "Pausing is useless for Release version.\n"
"To attach debugger use Debug built type."
<< rang::style::reset << '\n';
}
}
std::exit(signal);
......@@ -73,10 +83,9 @@ SignalManager::handler(int signal)
{
static std::mutex mutex;
if (mutex.try_lock()) {
std::signal(SIGTERM, SIG_DFL);
std::signal(SIGINT, SIG_DFL);
std::signal(SIGABRT, SIG_DFL);
std::lock_guard<std::mutex> lock(mutex);
std::signal(SIGINT, SIG_BLOCK);
// Each failing process must write
std::cerr.clear();
......@@ -120,9 +129,6 @@ SignalManager::handler(int signal)
}
SignalManager::pauseForDebug(signal);
mutex.unlock();
}
}
void
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment