X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fthread.cpp;h=a715d44ee17b2e5844e4be101b246041e9bc9c7d;hp=b4958ea32e22417527357b2b734e90fb0bf4eae8;hb=26dabb1e6bcd8035f0f3516c4358a73f2b041a1c;hpb=35b6079852ca2b1a12167e4b42b197501d2cc554 diff --git a/src/thread.cpp b/src/thread.cpp index b4958ea3..a715d44e 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -251,7 +251,7 @@ void MainThread::idle_loop() { while (!thinking && !exit) { - Threads.sleepCondition.notify_one(); // Wake up the UI thread if needed + sleepCondition.notify_one(); // Wake up the UI thread if needed sleepCondition.wait(lk); } @@ -271,6 +271,15 @@ void MainThread::idle_loop() { } +// MainThread::join() waits for main thread to finish the search + +void MainThread::join() { + + std::unique_lock lk(mutex); + sleepCondition.wait(lk, [&]{ return !thinking; }); +} + + // ThreadPool::init() is called at startup to create and launch requested threads, // that will go immediately to sleep. We cannot use a c'tor because Threads is a // static object and we need a fully initialized engine at this point due to @@ -337,21 +346,12 @@ Thread* ThreadPool::available_slave(const SplitPoint* sp) const { } -// ThreadPool::wait_for_think_finished() waits for main thread to finish the search - -void ThreadPool::wait_for_think_finished() { - - std::unique_lock lk(main()->mutex); - sleepCondition.wait(lk, [&]{ return !main()->thinking; }); -} - - // ThreadPool::start_thinking() wakes up the main thread sleeping in // MainThread::idle_loop() and starts a new search, then returns immediately. void ThreadPool::start_thinking(const Position& pos, const LimitsType& limits, StateStackPtr& states) { - wait_for_think_finished(); + main()->join(); SearchTime = now(); // As early as possible