if (do_terminate)
return;
- think(); // Search entry point
+ Search::think();
}
}
+// 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
Thread& main = threads[0];
+ // Wait main thread has finished before to launch a new search
+ wait_end_of_search();
+
lock_grab(&main.sleepLock);
- // Wait main thread has finished before to launch a new search
- while (!main.do_sleep)
- cond_wait(&sleepCond, &main.sleepLock);
+ // Reset signals before to start the search
+ memset((void*)&Search::Signals, 0, sizeof(Search::Signals));
main.do_sleep = false;
cond_signal(&main.sleepCond); // Wake up main thread
lock_release(&main.sleepLock);
}
+
+
+// ThreadsManager::wait_for_stop_or_ponderhit() is called when the maximum depth
+// is reached while the program is pondering. The point is to work around a wrinkle
+// in the UCI protocol: When pondering, the engine is not allowed to give a
+// "bestmove" before the GUI sends it a "stop" or "ponderhit" command.
+// We simply wait here until one of these commands (that raise StopRequest) is
+// sent, and return, after which the bestmove and pondermove will be printed.
+
+void ThreadsManager::wait_for_stop_or_ponderhit() {
+
+ Search::Signals.stopOnPonderhit = true;
+
+ Thread& main = threads[0];
+
+ lock_grab(&main.sleepLock);
+
+ while (!Search::Signals.stop)
+ cond_wait(&main.sleepCond, &main.sleepLock);
+
+ lock_release(&main.sleepLock);
+}