diff --git a/source/util-threadpool.cpp b/source/util-threadpool.cpp index 1fcc255..8d710af 100644 --- a/source/util-threadpool.cpp +++ b/source/util-threadpool.cpp @@ -51,15 +51,15 @@ void util::threadpool::push(threadpool_function_t fn, std::shared_ptr data void util::threadpool::work() { - std::pair> work; - while (!_worker_stop) { + std::pair> work; + // Wait for more work, or immediately continue if there is still work to do. { std::unique_lock lock(_tasks_lock); if (_tasks.size() == 0) _tasks_cv.wait(lock, [this]() { return _worker_stop || _tasks.size() > 0; }); - if (_tasks.size() == 0) + if (_worker_stop || (_tasks.size() == 0)) continue; work = _tasks.front(); _tasks.pop_front();