properly synchronize threads in InterpreterProcess
authormegacz <adam@megacz.com>
Fri, 16 Jan 2009 20:20:51 +0000 (12:20 -0800)
committermegacz <adam@megacz.com>
Fri, 16 Jan 2009 20:20:51 +0000 (12:20 -0800)
src/edu/berkeley/fleet/interpreter/Interpreter.java

index 0461167..50bcc20 100644 (file)
@@ -179,12 +179,12 @@ public class Interpreter extends FleetTwoFleet {
     public class InterpreterProcess extends FleetProcess implements Runnable {
         private Instruction[] instructions;
         public void flush() { }
-        public void sendWord(Destination d, BitVector word) {
+        public synchronized void sendWord(Destination d, BitVector word) {
             InterpreterPath path = (InterpreterPath)debugShip.getDock("in").getPath(d, new BitVector(1));
             ((InterpreterDestination)d).
                 addDataFromFabric(new Packet(path, word, false));
         }
-        public void sendToken(Destination d) {
+        public synchronized void sendToken(Destination d) {
             InterpreterPath path = (InterpreterPath)debugShip.getDock("in").getPath(d, new BitVector(1));
             ((InterpreterDestination)d).
                 addDataFromFabric(new Packet(path, new BitVector(getWordWidth()), true));
@@ -205,10 +205,13 @@ public class Interpreter extends FleetTwoFleet {
         protected void _terminate() { }
         public void run() {
             try {
-                while(!isTerminated())
+                while(!isTerminated()) {
                     for(InterpreterShip ship : ships.values())
                         for(int j=0; j<10; j++)
-                            ship._service();
+                            synchronized(this) {
+                                ship._service();
+                            }
+                }
                 for(InterpreterShip ship : ships.values())
                     ship.reset();
                 debugStream.clear();
@@ -218,11 +221,11 @@ public class Interpreter extends FleetTwoFleet {
             }
         }
 
-        public void step(Dock d) {
+        public synchronized void step(Dock d) {
             ((InterpreterDock)d).service();
         }
         
-        public void step(Ship s) {
+        public synchronized void step(Ship s) {
             ((InterpreterShip)s).service();
         }