]> git.sesse.net Git - stockfish/commitdiff
Fix broken UCI 'wait for stop'
authorMarco Costalba <mcostalba@gmail.com>
Mon, 9 Nov 2015 08:50:02 +0000 (09:50 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Fri, 13 Nov 2015 07:13:59 +0000 (08:13 +0100)
When we reach the maximum depth, we can finish the
search without a raise of Signals.stop. However, if
we are pondering or in an infinite search, the UCI
protocol states that we shouldn't print the best move
before the GUI sends a "stop" or "ponderhit" command.

It was broken by lazy smp. Fix it by moving the stopping
of the threads after waiting for GUI.

No functional change.

src/search.cpp

index 58a52831a729c9f69cd15fd9e72210c7fea6decc..205e992723108b2b90c750706235410c7da1baf9 100644 (file)
@@ -300,14 +300,6 @@ void MainThread::think() {
       }
 
       search(true); // Let's start searching!
       }
 
       search(true); // Let's start searching!
-
-      // Stop the threads
-      Signals.stop = true;
-
-      // Wait until all threads have finished
-      for (Thread* th : Threads)
-          if (th != this)
-              th->wait_while(th->searching);
   }
 
   // When playing in 'nodes as time' mode, subtract the searched nodes from
   }
 
   // When playing in 'nodes as time' mode, subtract the searched nodes from
@@ -326,6 +318,14 @@ void MainThread::think() {
       wait(Signals.stop);
   }
 
       wait(Signals.stop);
   }
 
+  // Stop the threads if not already stopped
+  Signals.stop = true;
+
+  // Wait until all threads have finished
+  for (Thread* th : Threads)
+      if (th != this)
+          th->wait_while(th->searching);
+
   // Check if there are threads with a better score than main thread.
   Thread* bestThread = this;
   for (Thread* th : Threads)
   // Check if there are threads with a better score than main thread.
   Thread* bestThread = this;
   for (Thread* th : Threads)