diff --git a/daggy/src/ThreadPool.cpp b/daggy/src/ThreadPool.cpp index 3e4963a..99d951a 100644 --- a/daggy/src/ThreadPool.cpp +++ b/daggy/src/ThreadPool.cpp @@ -3,6 +3,8 @@ using namespace daggy; ThreadPool::ThreadPool(size_t nWorkers) { + shutdown_ = false; + std::lock_guard lk(guard_); for (size_t i = 0; i < nWorkers; ++i) { workers_.emplace_back([&]() { while (true) { @@ -36,9 +38,11 @@ void ThreadPool::shutdown() { } std::future ThreadPool::addTask(std::function fn) { + std::packaged_task task(fn); + std::future result = task.get_future(); { std::unique_lock lk(guard_); - taskQueue_.push_back(fn); + taskQueue_.push_back(std::move(task)); } cv_.notify_one(); }