]> git.sesse.net Git - stockfish/blobdiff - src/thread.cpp
Fix an hang when max depth is reached
[stockfish] / src / thread.cpp
index 65d01d9100a874e19db9addea3772bafa735dd69..6fefd58a792b9225d7a121bf102e38e18a8850fc 100644 (file)
@@ -137,7 +137,6 @@ void Thread::main_loop() {
 void Thread::wake_up() {
 
   lock_grab(sleepLock);
-  do_sleep = false;
   cond_signal(sleepCond);
   lock_release(sleepLock);
 }
@@ -257,6 +256,7 @@ void ThreadsManager::wake_up() const {
   for (int i = 0; i < size(); i++)
   {
       threads[i]->maxPly = 0;
+      threads[i]->do_sleep = false;
 
       if (!useSleepingThreads)
           threads[i]->wake_up();
@@ -419,18 +419,17 @@ void ThreadsManager::wait_for_search_finished() {
 
   Thread* main = threads[0];
   lock_grab(main->sleepLock);
+  cond_signal(main->sleepCond); // In case is waiting for stop or ponderhit
   while (!main->do_sleep) cond_wait(sleepCond, main->sleepLock);
   lock_release(main->sleepLock);
 }
 
 
-// ThreadsManager::start_searching() is used by UI thread to wake up the main
-// thread parked in main_loop() and starting a new search. If async is true
-// then function returns immediately, otherwise caller is blocked waiting for
-// the search to finish.
+// ThreadsManager::start_searching() wakes up the main thread sleeping in
+// main_loop() so to start a new search, then returns immediately.
 
 void ThreadsManager::start_searching(const Position& pos, const LimitsType& limits,
-                                     const std::set<Move>& searchMoves, bool async) {
+                                     const std::set<Move>& searchMoves) {
   wait_for_search_finished();
 
   Signals.stopOnPonderhit = Signals.firstRootMove = false;
@@ -444,8 +443,6 @@ void ThreadsManager::start_searching(const Position& pos, const LimitsType& limi
       if (searchMoves.empty() || searchMoves.count(ml.move()))
           RootMoves.push_back(RootMove(ml.move()));
 
-  threads[0]->wake_up(); // Start main thread
-
-  if (!async)
-      wait_for_search_finished();
+  threads[0]->do_sleep = false;
+  threads[0]->wake_up();
 }