From 4da621eaba4496c0ee98b2fef36d47e00121be20 Mon Sep 17 00:00:00 2001 From: jihoonl Date: Tue, 22 Sep 2009 00:14:48 +0000 Subject: [PATCH] recovery. Thread.java got a new static start method --- Robust/src/ClassLibrary/JavaDSM/Task.java | 27 +++++ Robust/src/ClassLibrary/JavaDSM/Thread.java | 24 ++++ Robust/src/ClassLibrary/JavaDSM/Work.java | 118 ++++++++++++++++++++ 3 files changed, 169 insertions(+) create mode 100644 Robust/src/ClassLibrary/JavaDSM/Task.java create mode 100644 Robust/src/ClassLibrary/JavaDSM/Work.java diff --git a/Robust/src/ClassLibrary/JavaDSM/Task.java b/Robust/src/ClassLibrary/JavaDSM/Task.java new file mode 100644 index 00000000..c4119819 --- /dev/null +++ b/Robust/src/ClassLibrary/JavaDSM/Task.java @@ -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; + } + } +} diff --git a/Robust/src/ClassLibrary/JavaDSM/Thread.java b/Robust/src/ClassLibrary/JavaDSM/Thread.java index 4fb2c7b1..e1db40a4 100644 --- a/Robust/src/ClassLibrary/JavaDSM/Thread.java +++ b/Robust/src/ClassLibrary/JavaDSM/Thread.java @@ -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 index 00000000..56e18d1b --- /dev/null +++ b/Robust/src/ClassLibrary/JavaDSM/Work.java @@ -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 + } +} + -- 2.34.1