]> git.sesse.net Git - stockfish/commitdiff
After a "stop" do not read new input until search finishes
authorMarco Costalba <mcostalba@gmail.com>
Sun, 27 Nov 2011 11:16:23 +0000 (12:16 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 27 Nov 2011 11:19:33 +0000 (12:19 +0100)
Unfortunatly xboard sends immediately the new position to
search after sending "stop" when we have a ponder miss.

Becuase main thread position is not copied but is referenced
directly from root position and the latter is modified by
the "position.." UCI command we end up with the working position
that changes under our feet while the search is still recovering
after the "stop" and this causes a crash.

This happens only with the (broken) xboard, native UCI does not
have this problem.

Reported by otello1984

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/thread.cpp
src/thread.h
src/uci.cpp

index e48ea6fd38e6cc22188c5fb20029353f84966309..536f22c1194cf6912eb578f550cf1d298d21d959 100644 (file)
@@ -423,6 +423,23 @@ void Thread::main_loop() {
 }
 
 
+// ThreadsManager::wait_end_of_search() blocks UI thread until main thread has
+// returned to sleep in main_loop(). It is needed becuase xboard sends immediately
+// new position to search after a "stop" due to ponder miss.
+
+void ThreadsManager::wait_end_of_search() {
+
+  Thread& main = threads[0];
+
+  lock_grab(&main.sleepLock);
+
+  while (!main.do_sleep)
+      cond_wait(&sleepCond, &main.sleepLock);
+
+  lock_release(&main.sleepLock);
+}
+
+
 // ThreadsManager::start_thinking() is used by UI thread to wake up the main
 // thread parked in main_loop() and starting a new search. If asyncMode is true
 // then function returns immediately, otherwise caller is blocked waiting for
@@ -432,11 +449,10 @@ void ThreadsManager::start_thinking(bool asyncMode) {
 
   Thread& main = threads[0];
 
-  lock_grab(&main.sleepLock);
-
   // Wait main thread has finished before to launch a new search
-  while (!main.do_sleep)
-      cond_wait(&sleepCond, &main.sleepLock);
+  wait_end_of_search();
+
+  lock_grab(&main.sleepLock);
 
   // Reset signals before to start the search
   memset((void*)&Search::Signals, 0, sizeof(Search::Signals));
index df42c5aa756d0ff11ceb9cc34e720c5827d2ae8e..95ec1292ea0aa86c1abd93d6e3f11f7ba09e2c56 100644 (file)
@@ -120,6 +120,7 @@ public:
   void start_thinking(bool asyncMode = true);
   void set_timer(int msec);
   void wait_for_stop_or_ponderhit();
+  void wait_end_of_search();
 
   template <bool Fake>
   Value split(Position& pos, SearchStack* ss, Value alpha, Value beta, Value bestValue,
index 72e3d0bd0cd4600f5c1694c884ff769b1a1d6a66..57a31ad64f11f4bb0ef788a374ba67a3bd76e150 100644 (file)
@@ -72,6 +72,7 @@ void uci_loop() {
           quit = (token == "quit");
           Search::Signals.stop = true;
           Threads[0].wake_up(); // In case is waiting for stop or ponderhit
+          Threads.wait_end_of_search(); // Block here until search finishes
       }
 
       else if (cmd == "ponderhit")