diff --git a/src/thread.cpp b/src/thread.cpp index e4226769..874b09ee 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -98,6 +98,12 @@ void Thread::wait_for_search_finished() { } +void Thread::wait_for_task_finished() { + + std::unique_lock lk(mutex); + cv.wait(lk, [&]{ return !task; }); +} + /// Thread::idle_loop() is where the thread is parked, blocked on the /// condition variable, when it has no work to do. @@ -293,3 +299,10 @@ void ThreadPool::wait_for_search_finished() const { if (th != front()) th->wait_for_search_finished(); } + + +void ThreadPool::wait_for_tasks_finished() const { + + for (Thread* th : *this) + th->wait_for_task_finished(); +} diff --git a/src/thread.h b/src/thread.h index 8e9e6fba..8be6eb5a 100644 --- a/src/thread.h +++ b/src/thread.h @@ -56,6 +56,7 @@ public: void idle_loop(); void start_searching(); void wait_for_search_finished(); + void wait_for_task_finished(); size_t thread_idx() const { return idx; } Pawns::Table pawnsTable; @@ -121,6 +122,7 @@ struct ThreadPool : public std::vector { Thread* get_best_thread() const; void start_searching(); void wait_for_search_finished() const; + void wait_for_tasks_finished() const; std::atomic_bool stop, increaseDepth;