mirror of
https://github.com/NixOS/nix.git
synced 2025-11-13 22:12:43 +01:00
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
|
|
@ -55,9 +55,10 @@ void ThreadPool::process()
|
|||
work();
|
||||
} catch (std::exception & e) {
|
||||
auto state_(state.lock());
|
||||
if (state_->exception)
|
||||
printMsg(lvlError, format("error: %s") % e.what());
|
||||
else {
|
||||
if (state_->exception) {
|
||||
if (!dynamic_cast<Interrupted*>(&e))
|
||||
printMsg(lvlError, format("error: %s") % e.what());
|
||||
} else {
|
||||
state_->exception = std::current_exception();
|
||||
wakeup.notify_all();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue