X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=e93c5045578193a5e493e1000e34ae8eb7990518;hp=673d3a230ec5257809eeab33576e9611d62489cf;hb=df6cb446eaf21;hpb=dbc984d9f87ba79db3c7802310450f60e95e89e4 diff --git a/src/search.cpp b/src/search.cpp index 673d3a23..e93c5045 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -183,10 +183,13 @@ void Search::init() { } -/// Search::clear() resets search state to its initial value, to obtain reproducible results +/// Search::clear() resets search state to its initial value void Search::clear() { + Threads.main()->wait_for_search_finished(); + + Time.availableNodes = 0; TT.clear(); for (Thread* th : Threads) @@ -274,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 && (Limits.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 @@ -338,7 +341,6 @@ void Thread::search() { bestValue = delta = alpha = -VALUE_INFINITE; beta = VALUE_INFINITE; - completedDepth = DEPTH_ZERO; if (mainThread) { @@ -496,7 +498,7 @@ void Thread::search() { { // If we are allowed to ponder do not stop the search now but // keep pondering until the GUI sends "ponderhit" or "stop". - if (Limits.ponder) + if (Threads.ponder) Threads.stopOnPonderhit = true; else Threads.stop = true; @@ -1486,7 +1488,7 @@ moves_loop: // When in check search starts from here } // An engine may not stop pondering until told so by the GUI - if (Limits.ponder) + if (Threads.ponder) return; if ( (Limits.use_time_management() && elapsed > Time.maximum() - 10)