decouple the insertion of shutdown commands from the readback of shutdown tokens
authoradam <adam@megacz.com>
Mon, 17 Nov 2008 01:36:16 +0000 (02:36 +0100)
committeradam <adam@megacz.com>
Mon, 17 Nov 2008 01:36:16 +0000 (02:36 +0100)
src/edu/berkeley/fleet/ir/Process.java

index a6b017a..df3add3 100644 (file)
@@ -1,4 +1,5 @@
 package edu.berkeley.fleet.ir;
+import java.util.concurrent.Semaphore;
 import java.util.*;
 import java.net.*;
 import edu.berkeley.fleet.two.*;
@@ -726,15 +727,27 @@ public class Process {
             System.out.println("== phase "+phase+" ==================================================================");
             ctx2 = new Context(fp.getFleet());
             proc.reset(ctx2, phase);
+
+            final Semaphore sem = new Semaphore(0);
+            final FleetProcess fpf = fp;
+            final int phasef = phase;
+            new Thread() {
+                public void run() {
+                    for(int ii=0; ii<reset_count; ii++) {
+                        System.out.print("\r phase "+phasef+" ==> " + (ii+1) + " / " + reset_count);
+                        fpf.recvWord();
+                    }
+                    sem.release();
+                }}.start();
+
             for(Dock dock : torpedoes) fp.sendToken(dock.getInstructionDestination());
             ctx2.emit(ai = new ArrayList<Instruction>());
             for(Instruction ins : ai) fp.sendInstruction(ins);
             fp.flush();
+
+            sem.acquire();
             System.out.println("flushed");
-            for(int ii=0; ii<reset_count; ii++) {
-                System.out.print("\r phase "+phase+" ==> " + (ii+1) + " / " + reset_count);
-                fp.recvWord();
-            }
+
             System.out.println();
         }