diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2016-03-29 15:08:24 +0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2016-03-29 16:37:16 +0200 |
commit | ab3ce1cc13153b2053302cdb710cb411b0b9d84e (patch) | |
tree | 1548ea7b5316f7793cdb44d0da2642dafa1d4441 /src/libutil/thread-pool.cc | |
parent | 4f34c403980e7f5ae3d5257b742af6fd6452c6cf (diff) |
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.
Diffstat (limited to 'src/libutil/thread-pool.cc')
-rw-r--r-- | src/libutil/thread-pool.cc | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/libutil/thread-pool.cc b/src/libutil/thread-pool.cc index 819aed748..743038b58 100644 --- a/src/libutil/thread-pool.cc +++ b/src/libutil/thread-pool.cc @@ -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(); } |