Skip to content
Snippets Groups Projects
Commit e682a8e1 authored by Eelco Dolstra's avatar Eelco Dolstra
Browse files

Fix assertion failure in ThreadPool::enqueue()

parent d57981ba
No related branches found
No related tags found
No related merge requests found
...@@ -36,7 +36,8 @@ ThreadPool::~ThreadPool() ...@@ -36,7 +36,8 @@ ThreadPool::~ThreadPool()
void ThreadPool::enqueue(const work_t & t) void ThreadPool::enqueue(const work_t & t)
{ {
auto state(state_.lock()); auto state(state_.lock());
assert(!state->quit); if (state->quit)
throw ThreadPoolShutDown("cannot enqueue a work item while the thread pool is shutting down");
state->left.push(t); state->left.push(t);
if (state->left.size() > state->workers.size() && state->workers.size() < maxThreads) if (state->left.size() > state->workers.size() && state->workers.size() < maxThreads)
state->workers.emplace_back(&ThreadPool::workerEntry, this); state->workers.emplace_back(&ThreadPool::workerEntry, this);
...@@ -84,7 +85,8 @@ void ThreadPool::workerEntry() ...@@ -84,7 +85,8 @@ void ThreadPool::workerEntry()
} catch (std::exception & e) { } catch (std::exception & e) {
auto state(state_.lock()); auto state(state_.lock());
if (state->exception) { if (state->exception) {
if (!dynamic_cast<Interrupted*>(&e)) if (!dynamic_cast<Interrupted*>(&e) &&
!dynamic_cast<ThreadPoolShutDown*>(&e))
printMsg(lvlError, format("error: %s") % e.what()); printMsg(lvlError, format("error: %s") % e.what());
} else { } else {
state->exception = std::current_exception(); state->exception = std::current_exception();
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
namespace nix { namespace nix {
MakeError(ThreadPoolShutDown, Error)
/* A simple thread pool that executes a queue of work items /* A simple thread pool that executes a queue of work items
(lambdas). */ (lambdas). */
class ThreadPool class ThreadPool
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment