Add new Barrier ...will need to change it to a better implementation
authoradash <adash>
Wed, 15 Apr 2009 23:48:28 +0000 (23:48 +0000)
committeradash <adash>
Wed, 15 Apr 2009 23:48:28 +0000 (23:48 +0000)
Robust/src/ClassLibrary/JavaSTM/Barrier.java [new file with mode: 0644]

diff --git a/Robust/src/ClassLibrary/JavaSTM/Barrier.java b/Robust/src/ClassLibrary/JavaSTM/Barrier.java
new file mode 100644 (file)
index 0000000..f8389c4
--- /dev/null
@@ -0,0 +1,52 @@
+public class BarrierServer extends Thread {
+  int numthreads;
+  boolean done;
+
+  public BarrierServer(int n) {
+    numthreads=n;
+    done=false;
+  }
+
+  public void run() {
+    int n;
+    ServerSocket ss=new ServerSocket(2000);
+    atomic {
+      n=numthreads;
+      done=true;
+    }
+    Socket ar[]=new Socket[n];
+    for(int i=0; i<n; i++) {
+      ar[i]=ss.accept();
+    }
+
+    while(true) {
+      for(int j=0; j<n; j++) {
+       Socket s=ar[j];
+       byte b[]=new byte[1];
+       while(s.read(b)!=1) {
+         ;
+       }
+      }
+      byte b[]=new byte[1];
+      b[0]= (byte) 'A';
+      for(int j=0; j<n; j++)
+       ar[j].write(b);
+    }
+  }
+}
+
+public class Barrier {
+  Socket s;
+  public Barrier(String name) {
+    s=new Socket(name, 2000);
+  }
+
+  public static void enterBarrier(Barrier barr) {
+    byte b[]=new byte[1];
+    b[0]=(byte)'A';
+    barr.s.write(b);
+    while(barr.s.read(b)!=1) {
+      ;
+    }
+  }
+}