Improve SIGINT handling in multi-threaded programs
The flag remembering whether an Interrupted exception was thrown is now thread-local. Thus, all threads will (eventually) throw Interrupted. Previously, one thread would throw Interrupted, and then the other threads wouldn't see that they were supposed to quit.
This commit is contained in:
parent
4f34c40398
commit
ab3ce1cc13
4 changed files with 12 additions and 14 deletions
|
@ -24,15 +24,9 @@
|
|||
namespace nix {
|
||||
|
||||
|
||||
volatile sig_atomic_t blockInt = 0;
|
||||
|
||||
|
||||
static void sigintHandler(int signo)
|
||||
{
|
||||
if (!blockInt) {
|
||||
_isInterrupted = 1;
|
||||
blockInt = 1;
|
||||
}
|
||||
_isInterrupted = 1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -287,8 +281,7 @@ int handleExceptions(const string & programName, std::function<void()> fun)
|
|||
condition is discharged before we reach printMsg()
|
||||
below, since otherwise it will throw an (uncaught)
|
||||
exception. */
|
||||
blockInt = 1; /* ignore further SIGINTs */
|
||||
_isInterrupted = 0;
|
||||
interruptThrown = true;
|
||||
throw;
|
||||
}
|
||||
} catch (Exit & e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue