mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-25 03:26:24 +08:00
allow waiting for task completion.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user