Fix running of clock during hash allocation engine
authorH.G. Muller <h.g.muller@hccnet.nl>
Fri, 15 Apr 2011 13:41:38 +0000 (15:41 +0200)
committerH.G. Muller <h.g.muller@hccnet.nl>
Fri, 15 Apr 2011 13:41:38 +0000 (15:41 +0200)
In TwoMachinesEvent we now wait for the second engine to acknowledge the
'ping' after 'new', to make sure it is done allocating hash in reaction
to the preceding 'memory' command, before the clock for the game is
started.

backend.c

index 9f9f63e..677e21c 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -12084,6 +12084,7 @@ TwoMachinesEvent P((void))
     char buf[MSG_SIZ];
     ChessProgramState *onmove;
     char *bookHit = NULL;
+    static int stalling = 0;
 
     if (appData.noChessProgram) return;
 
@@ -12120,13 +12121,23 @@ TwoMachinesEvent P((void))
     ResurrectChessProgram();   /* in case first program isn't running */
 
     if(WaitForSecond(TwoMachinesEventIfReady)) return;
-    DisplayMessage("", "");
-    InitChessProgram(&second, FALSE);
-    SendToProgram("force\n", &second);
     if(first.lastPing != first.lastPong) { // [HGM] wait till we are sure first engine has set up position
+      DisplayMessage("", _("Waiting for first chess program"));
+      ScheduleDelayedEvent(TwoMachinesEvent, 10);
+      return;
+    }
+    if(!stalling) {
+      InitChessProgram(&second, FALSE);
+      SendToProgram("force\n", &second);
+    }
+    if(second.lastPing != second.lastPong) { // [HGM] second engine might have to reallocate hash
+      if(!stalling) DisplayMessage("", _("Waiting for second chess program"));
+      stalling = 1;
       ScheduleDelayedEvent(TwoMachinesEvent, 10);
       return;
     }
+    stalling = 0;
+    DisplayMessage("", "");
     if (startedFromSetupPosition) {
        SendBoard(&second, backwardMostMove);
     if (appData.debugMode) {