From: megacz Date: Fri, 16 Jan 2009 20:20:51 +0000 (-0800) Subject: properly synchronize threads in InterpreterProcess X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=a3f9fc2b747c0779187efd93471bdad946d80cd6;p=fleet.git properly synchronize threads in InterpreterProcess --- diff --git a/src/edu/berkeley/fleet/interpreter/Interpreter.java b/src/edu/berkeley/fleet/interpreter/Interpreter.java index 0461167..50bcc20 100644 --- a/src/edu/berkeley/fleet/interpreter/Interpreter.java +++ b/src/edu/berkeley/fleet/interpreter/Interpreter.java @@ -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(); }