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();
}