]> git.sesse.net Git - stockfish/commitdiff
Simplify finished search in ponder/infinite mode.
authorJoost VandeVondele <Joost.VandeVondele@gmail.com>
Fri, 4 Aug 2017 17:48:07 +0000 (19:48 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Fri, 11 Aug 2017 05:42:52 +0000 (22:42 -0700)
In this rare case (e.g. go infinite on a stalemate),
just spin till ponderhit/stop comes.

The Thread::wait() is a renmant of the old YBWC
code, today with lazy SMP, threads don't need to
wait when outside of their idle loop.

No functional change.

src/search.cpp
src/thread.cpp
src/thread.h
src/uci.cpp

index 3c638ca057f5e1c3c515498e005cecf88a111c8e..68069c23c5afc610c0c949c58a3b29315575a676 100644 (file)
@@ -277,13 +277,13 @@ void MainThread::search() {
   // the UCI protocol states that we shouldn't print the best move before the
   // GUI sends a "stop" or "ponderhit" command. We therefore simply wait here
   // until the GUI sends one of those commands (which also raises Threads.stop).
-  if (!Threads.stop && (Threads.ponder || Limits.infinite))
-  {
-      Threads.stopOnPonderhit = true;
-      wait(Threads.stop);
-  }
+  Threads.stopOnPonderhit = true;
+
+  while (!Threads.stop && (Threads.ponder || Limits.infinite))
+  {} // Busy wait for a stop or a ponder reset
 
-  // Stop the threads if not already stopped
+  // Stop the threads if not already stopped (also raise the stop if
+  // "ponderhit" just reset Threads.ponder).
   Threads.stop = true;
 
   // Wait until all threads have finished
index 6d3364d5c56525c1bdad9fc8af803ce8ed2234e2..c602e0b46a873a60ae6a02d117d8d70347206829 100644 (file)
@@ -68,24 +68,12 @@ void Thread::wait_for_search_finished() {
 }
 
 
-/// Thread::wait() waits on sleep condition until condition is true
-
-void Thread::wait(std::atomic_bool& condition) {
-
-  std::unique_lock<Mutex> lk(mutex);
-  sleepCondition.wait(lk, [&]{ return bool(condition); });
-}
-
-
 /// Thread::start_searching() wakes up the thread that will start the search
 
-void Thread::start_searching(bool resume) {
+void Thread::start_searching() {
 
   std::unique_lock<Mutex> lk(mutex);
-
-  if (!resume)
-      searching = true;
-
+  searching = true;
   sleepCondition.notify_one();
 }
 
index ee43bfb5ba19f7afb7b43f50f45c6377d7574f55..9b2e359b972b5e3fab9f2babe84f589c9e3ead7a 100644 (file)
@@ -52,9 +52,8 @@ public:
   virtual ~Thread();
   virtual void search();
   void idle_loop();
-  void start_searching(bool resume = false);
+  void start_searching();
   void wait_for_search_finished();
-  void wait(std::atomic_bool& condition);
 
   Pawns::Table pawnsTable;
   Material::Table materialTable;
index 58b38779ee2bec226c5cd29002ef345ba3a221c0..a56a54031d07722673f4e95368a01b22a8b64175 100644 (file)
@@ -176,10 +176,8 @@ void UCI::loop(int argc, char* argv[]) {
       if (    token == "quit"
           ||  token == "stop"
           || (token == "ponderhit" && Threads.stopOnPonderhit))
-      {
           Threads.stop = true;
-          Threads.main()->start_searching(true); // Could be sleeping
-      }
+
       else if (token == "ponderhit")
           Threads.ponder = false; // Switch to normal search