allow waiting for task completion.

This commit is contained in:
Tomasz Sobczyk
2020-10-18 10:34:48 +02:00
committed by nodchip
parent 5188c26b20
commit 97fb9a89e4
2 changed files with 15 additions and 0 deletions

View File

@@ -98,6 +98,12 @@ void Thread::wait_for_search_finished() {
}
void Thread::wait_for_task_finished() {
std::unique_lock<std::mutex> 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();
}

View File

@@ -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*> {
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;