about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-07-21T16·14+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-07-21T16·14+0200
commite682a8e138c44e557c57a8dcf33555ad7790dd8c (patch)
tree5ededcfcb0d79cb5148b4ed54b8215b85383566d /src
parentd57981bac488e5928218e0eaeae58bd817c74727 (diff)
Fix assertion failure in ThreadPool::enqueue()
Diffstat (limited to 'src')
-rw-r--r--src/libutil/thread-pool.cc6
-rw-r--r--src/libutil/thread-pool.hh2
2 files changed, 6 insertions, 2 deletions
diff --git a/src/libutil/thread-pool.cc b/src/libutil/thread-pool.cc
index 32363ecf0098..696ecd6c38c8 100644
--- a/src/libutil/thread-pool.cc
+++ b/src/libutil/thread-pool.cc
@@ -36,7 +36,8 @@ ThreadPool::~ThreadPool()
 void ThreadPool::enqueue(const work_t & t)
 {
     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);
     if (state->left.size() > state->workers.size() && state->workers.size() < maxThreads)
         state->workers.emplace_back(&ThreadPool::workerEntry, this);
@@ -84,7 +85,8 @@ void ThreadPool::workerEntry()
         } catch (std::exception & e) {
             auto state(state_.lock());
             if (state->exception) {
-                if (!dynamic_cast<Interrupted*>(&e))
+                if (!dynamic_cast<Interrupted*>(&e) &&
+                    !dynamic_cast<ThreadPoolShutDown*>(&e))
                     printMsg(lvlError, format("error: %s") % e.what());
             } else {
                 state->exception = std::current_exception();
diff --git a/src/libutil/thread-pool.hh b/src/libutil/thread-pool.hh
index 78b63467d62e..b64dc52d473e 100644
--- a/src/libutil/thread-pool.hh
+++ b/src/libutil/thread-pool.hh
@@ -10,6 +10,8 @@
 
 namespace nix {
 
+MakeError(ThreadPoolShutDown, Error)
+
 /* A simple thread pool that executes a queue of work items
    (lambdas). */
 class ThreadPool