-// ThreadsManager::stop_listener() is called before to send "bestmove" to GUI to
-// return to in-sync behaviour. This is needed because while in async mode any
-// command is discarded without being processed (except for a very few ones).
+// 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
+// then return, after which the bestmove and pondermove will be printed.
+
+void ThreadsManager::wait_for_stop_or_ponderhit() {
+
+ Signals.stopOnPonderhit = true;
+
+ Thread& main = threads[0];