recovery.
authorjihoonl <jihoonl>
Tue, 22 Sep 2009 00:14:48 +0000 (00:14 +0000)
committerjihoonl <jihoonl>
Tue, 22 Sep 2009 00:14:48 +0000 (00:14 +0000)
 Thread.java got a new static start method

Robust/src/ClassLibrary/JavaDSM/Task.java [new file with mode: 0644]
Robust/src/ClassLibrary/JavaDSM/Thread.java
Robust/src/ClassLibrary/JavaDSM/Work.java [new file with mode: 0644]

diff --git a/Robust/src/ClassLibrary/JavaDSM/Task.java b/Robust/src/ClassLibrary/JavaDSM/Task.java
new file mode 100644 (file)
index 0000000..c411981
--- /dev/null
@@ -0,0 +1,27 @@
+public class Task {
+  Queue todoList;
+       Queue doneList;
+
+       Task() {}
+
+       public void init();     
+       public void execute(Object work);
+       public void done(Object work);
+
+       public Object grabTask() {
+               Object o;
+               atomic {
+                       o = todoList.pop();
+               }
+               return o;
+       }
+
+       public boolean isTodoListEmpty() {
+               if (todoList.size() == 0) {
+                       return true;
+               }
+               else {
+                       return false;
+               }
+       }
+}
index 4fb2c7b1418a91456d455e191b8e935a060f1aa1..e1db40a44b50ec3ea9040745e39afd6dcacd1ed3 100644 (file)
@@ -2,6 +2,7 @@ public class Thread {
   /* Don't allow overriding this method.  If you do, it will break dispatch
    * because we don't have the type information necessary. */
   public boolean threadDone;
+  public int mid;
 
   public Thread() {
     threadDone = false;
@@ -13,8 +14,31 @@ public class Thread {
 
   public final native void start(int mid);
 
+  public static void myStart(Thread t, int mid)
+  {
+    atomic  {
+      t.mid = mid;
+    }
+    t.start(mid);
+  }
+
+  public native static int nativeGetStatus(int mid);
+
   public native static void sleep(long millis);
 
   public void run() {
   }
+
+  public static int getStatus(int mid)
+  {
+    if(nativeGetStatus(mid)==1)
+      return 1;
+    else
+      return -1;
+
+  }
 }
+
+
+
+
diff --git a/Robust/src/ClassLibrary/JavaDSM/Work.java b/Robust/src/ClassLibrary/JavaDSM/Work.java
new file mode 100644 (file)
index 0000000..56e18d1
--- /dev/null
@@ -0,0 +1,118 @@
+public class Work extends Thread {
+  Task tasks;
+       Object[] currentWorkList;
+       int MY_MID;
+       int NUM_THREADS;
+
+       Work (Task tasks, int num_threads, int mid, Object[] currentWorkList) {
+               this.tasks = tasks;
+               this.currentWorkList = currentWorkList;
+               NUM_THREADS = num_threads;
+               MY_MID = mid;
+       }
+
+       public void run() {
+    int workMID;
+    atomic {
+      workMID = MY_MID;
+    }
+
+    int chk; 
+    int result;
+    int i,j;
+    int cc;
+               boolean isEmpty; 
+
+    while(true) {
+      atomic {
+                                       isEmpty = tasks.isTodoListEmpty();              // flag > !keep assigning 
+                       
+          if (!isEmpty) {
+                             atomic {
+                               currentWorkList[workMID] = tasks.grabTask();    /* grab the work from work pool */
+                               }
+            chk = 1;
+          }
+                       else {
+            chk = Work.checkCurrentWorkList(this);
+        }
+      }
+
+      if(chk == 1) {    // still have work
+        atomic {
+          /* compute */
+          tasks.execute(currentWorkList[workMID]);
+          /* push into done list */
+          tasks.done(currentWorkList[workMID]);
+                                       currentWorkList[workMID] = null;
+        }
+
+        atomic {
+          cc = ((Drinker)tasks).ownTotal;
+        }
+
+//        System.out.println("CC = " + cc);
+//        sleep(1000000);
+      }
+      else if(chk  == -1) {    // finished all work
+        break;
+      }
+      else {    // wait for other thread
+                               sleep(5000000); 
+      }
+
+    }
+
+    /* for debugging purpose */
+    atomic {
+      System.out.println("\n\nDoneSize = " + tasks.doneList.size());
+    }
+    System.out.println("\n\n\n I'm done");
+
+  }
+
+       public static int checkCurrentWorkList(Work mywork) {           
+    int i;
+    int index = -1;
+    int myID;
+               int num_threads; 
+    int status;
+    boolean chk = false;
+    Segment s;
+
+               atomic {
+           myID = mywork.MY_MID;
+                       num_threads = mywork.NUM_THREADS;
+               }
+
+    for(i = 0 ; (i < num_threads) && (index < 0); i++) {
+      if(myID == i) {
+        continue;
+      }
+                       status = Thread.getStatus(i);
+
+      atomic {
+
+        s = (Segment)mywork.currentWorkList[i];
+
+        if(status == -1 && null != s) {
+          mywork.currentWorkList[myID] = mywork.currentWorkList[i];
+          mywork.currentWorkList[i] = null;
+          index = 0;
+        }
+        else if(null != s) {
+          chk = true;
+        }
+      }
+                       
+    }
+
+    if(index == 0)  // grabbed dead machine's work
+      return 1;
+    else if(i == num_threads && index < 0 && chk != true)  // wait for other machine's work
+      return -1;
+    else
+      return 0; // others are still working wait until they finish work
+  }
+}
+