diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0a9f9d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.build* + +.ccls_cache* diff --git a/ThreadPool.h b/ThreadPool.h index 4183203..a51136c 100644 --- a/ThreadPool.h +++ b/ThreadPool.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -44,10 +45,12 @@ inline ThreadPool::ThreadPool(size_t threads) { std::unique_lock lock(this->queue_mutex); - this->condition.wait(lock, + this->condition.wait_for(lock, std::chrono::milliseconds(200), [this]{ return this->stop || !this->tasks.empty(); }); - if(this->stop && this->tasks.empty()) + if(this->stop) return; + if(this->tasks.empty()) + continue; task = std::move(this->tasks.front()); this->tasks.pop(); }