Detach search arguments from UI thread
[stockfish] / src / uci.cpp
index 57a31ad64f11f4bb0ef788a374ba67a3bd76e150..306819bb3e46f680544f4a0b0fea69a9f6921782 100644 (file)
@@ -72,7 +72,6 @@ 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")
@@ -206,18 +205,16 @@ namespace {
   void go(Position& pos, istringstream& is) {
 
     string token;
+    Search::LimitsType limits;
+    std::vector<Move> searchMoves;
     int time[] = { 0, 0 }, inc[] = { 0, 0 };
 
-    memset(&Search::Limits, 0, sizeof(Search::Limits));
-    Search::RootMoves.clear();
-    Search::RootPosition = &pos;
-
     while (is >> token)
     {
         if (token == "infinite")
-            Search::Limits.infinite = true;
+            limits.infinite = true;
         else if (token == "ponder")
-            Search::Limits.ponder = true;
+            limits.ponder = true;
         else if (token == "wtime")
             is >> time[WHITE];
         else if (token == "btime")
@@ -227,23 +224,22 @@ namespace {
         else if (token == "binc")
             is >> inc[BLACK];
         else if (token == "movestogo")
-            is >> Search::Limits.movesToGo;
+            is >> limits.movesToGo;
         else if (token == "depth")
-            is >> Search::Limits.maxDepth;
+            is >> limits.maxDepth;
         else if (token == "nodes")
-            is >> Search::Limits.maxNodes;
+            is >> limits.maxNodes;
         else if (token == "movetime")
-            is >> Search::Limits.maxTime;
+            is >> limits.maxTime;
         else if (token == "searchmoves")
             while (is >> token)
-                Search::RootMoves.push_back(move_from_uci(pos, token));
+                searchMoves.push_back(move_from_uci(pos, token));
     }
+    searchMoves.push_back(MOVE_NONE);
+    limits.time = time[pos.side_to_move()];
+    limits.increment = inc[pos.side_to_move()];
 
-    Search::RootMoves.push_back(MOVE_NONE);
-    Search::Limits.time = time[pos.side_to_move()];
-    Search::Limits.increment = inc[pos.side_to_move()];
-
-    Threads.start_thinking();
+    Threads.start_thinking(pos, limits, searchMoves, true);
   }