--- /dev/null
+public class Drinker extends Task {
+ int ownTotal;
+
+ public Drinker(int num_threads,Queue todo,Queue done) {
+ ownTotal = 0;
+ todoList = todo;
+ doneList = done;
+ }
+
+ // fill up the Work Pool
+ public void fillTodoList(Queue todoList, int size) {
+ Segment seg;
+ int i;
+
+ for(i = 0; i < size; i += 10) {
+ seg = global new Segment(10);
+ todoList.push(seg);
+ }
+
+ System.out.println("TodoSIZE = " + todoList.size());
+ }
+
+ public Object grabTask() {
+ atomic {
+ if (todoList.size() != 0) {
+ return (Segment)todoList.pop();
+ }
+ }
+ return null;
+ }
+
+ public void execute(Object myWork) {
+ Segment work = (Segment)myWork;
+
+ int numApple = work.x;
+
+ ownTotal += numApple;
+
+ }
+
+ public void done(Object work) {
+ atomic {
+ doneList.push(work);
+ }
+ }
+
+ public static void main(String[] args) {
+ int NUM_THREADS;
+ int i,j;
+ int size = Integer.parseInt(args[1]);
+ Work[] work;
+ Drinker[] drinkers;
+ Segment[] currentWorkList;
+ Queue todoList;
+ Queue doneList;
+
+ if (args.length > 0) {
+ NUM_THREADS = Integer.parseInt(args[0]);
+ }
+
+ int[] mid = new int[NUM_THREADS];
+// mid[0] = (128<<24)|(195<<16)|(136<<8)|162; //dc1
+// mid[1] = (128<<24)|(195<<16)|(136<<8)|163; //dc2
+ mid[0] = (128<<24)|(195<<16)|(136<<8)|164; //dc3
+ mid[1] = (128<<24)|(195<<16)|(136<<8)|165; //dc4
+ mid[2] = (128<<24)|(195<<16)|(136<<8)|166; //dc5
+ mid[3] = (128<<24)|(195<<16)|(136<<8)|167; //dc6
+ mid[4] = (128<<24)|(195<<16)|(136<<8)|168; //dc7
+ mid[5] = (128<<24)|(195<<16)|(136<<8)|169; //dc8
+
+ atomic {
+ drinkers = global new Drinker[NUM_THREADS];
+ todoList = global new Queue(500);
+ doneList = global new Queue(500);
+
+ work = global new Work[NUM_THREADS];
+ currentWorkList = global new Segment[NUM_THREADS];
+
+ drinkers[0] = global new Drinker(NUM_THREADS,todoList,doneList);
+ drinkers[0].fillTodoList(todoList,size);
+ work[0] = global new Work(drinkers[0], NUM_THREADS, 0 , currentWorkList);
+
+ for(i = 1; i < NUM_THREADS; i++) {
+ drinkers[i] = global new Drinker(NUM_THREADS,todoList,doneList);
+ work[i] = global new Work(drinkers[i], NUM_THREADS, i,currentWorkList);
+ }
+ }
+
+ System.out.println("Finished initialization");
+ Work tmp;
+ for (i = 0; i < NUM_THREADS; i++) {
+ atomic {
+ tmp = work[i];
+ }
+ Thread.myStart(tmp,mid[i]);
+ }
+
+ System.out.println("Finished Starting Threads");
+ for (i = 0; i < NUM_THREADS; i++) {
+ atomic {
+ tmp = work[i];
+ }
+ System.out.println("Thread id " + i + " is joining");
+ tmp.join();
+ }
+
+ System.printString("Finished\n");
+ }
+}
+
+public class Segment {
+ int x;
+
+ Segment (int x) {
+ this.x = x;
+ }
+
+ public String toString()
+ {
+ return "lol";
+ }
+}
+
--- /dev/null
+public class Simple extends Thread {
+ Counting mycount;
+ int id;
+ public Simple(Counting mycount, int i) {
+ this.mycount = mycount;
+ this.id = i;
+ }
+
+ public void run() {
+
+ int threadid;
+
+ atomic {
+ threadid = id;
+// System.println("\n##threadid: " + threadid + "\n");
+ }
+// if(threadid == ((128<<24)|(195<<16)|(180<<8)|24))
+ // System.exit(0);
+
+ for(int i = 0; i < 1000; i++) {
+ atomic {
+// System.println("##threadid: " + threadid);
+ mycount.increment();
+ }
+
+// if(threadid == ((128<<24)|(195<<16)|(180<<8)|21)) {
+ for(int j =0;j< 4;j++) {
+ atomic {
+ // System.out.println("##Threadid " + j + " : " + getStatus(j));
+ }
+ }
+ // }
+ }
+
+ FileOutputStream output = new FileOutputStream("output"+threadid);
+ int cc;
+
+ atomic {
+ cc = mycount.count;
+ }
+
+ String outStr = "Count = " + cc + "\n";
+ output.write(outStr.getBytes());
+ System.out.println("\n\n\nFinished!!!!!!\n\n\n\n");
+ output.close();
+
+
+ }
+
+ public static void main(String[] args) {
+ Simple[] s;
+ Counting c;
+ int numthreads = 3;
+ int[] mid = new int[numthreads];
+ FileOutputStream out = new FileOutputStream("output");
+
+/* mid[0] = (128<<24)|(195<<16)|(180<<8)|26; //dw-7
+ mid[1] = (128<<24)|(195<<16)|(180<<8)|24; //dw-5
+ mid[2] = (128<<24)|(195<<16)|(180<<8)|21; //dw-2
+*/
+// mid[1] = (128<<24)|(195<<16)|(180<<8)|22; //dw-3
+ mid[0] = (128<<24)|(195<<16)|(136<<8)|162; //dc-1
+ mid[1] = (128<<24)|(195<<16)|(136<<8)|163; //dc-2
+ mid[2] = (128<<24)|(195<<16)|(136<<8)|164; //dc-3
+ mid[2] = (128<<24)|(195<<16)|(136<<8)|164; //dc-3
+ mid[2] = (128<<24)|(195<<16)|(136<<8)|164; //dc-3
+ mid[2] = (128<<24)|(195<<16)|(136<<8)|164; //dc-3
+ mid[2] = (128<<24)|(195<<16)|(136<<8)|164; //dc-3
+ mid[2] = (128<<24)|(195<<16)|(136<<8)|164; //dc-3
+// mid[3] = (128<<24)|(195<<16)|(136<<8)|165; //dc-4
+
+
+ atomic {
+
+ c = global new Counting();
+ s = global new Simple[numthreads];
+ for(int i = 0; i < numthreads; i++) {
+ s[i] = global new Simple(c, mid[i]);
+ }
+
+ }
+
+ ccc od = new ccc();
+ ddd ad = new ddd();
+ od.increment();
+
+ od.increment(3);
+
+ od = (ccc)ad;
+
+ od.increment(5);
+
+
+
+
+ System.out.println("##Done creating objects");
+ Simple tmp;
+ for(int i = 0; i < numthreads; i++) {
+ atomic {
+ tmp = s[i];
+ }
+ System.out.println("##Temp gets simple object; start temp simple object");
+// tmp.start(mid[i]);
+ Thread.myStart(tmp,mid[i]);
+ }
+
+ System.out.println("\n\n##DONE starting Threads\n");
+
+ for(int i = 0; i < numthreads; i++) {
+ atomic {
+ tmp = s[i];
+ }
+ System.out.println("##Wait\n");
+ tmp.join();
+ }
+ //print count
+ int finalcount;
+ atomic {
+ finalcount = c.count;
+ }
+
+ String outStr = "Count = " + finalcount + "\n";
+ out.write(outStr.getBytes());
+ System.printString("Count = "+finalcount+"\n");
+ out.close();
+
+ }
+
+}
+
+class Counting {
+ global int count;
+ public Counting() {
+ this.count = 0;
+ }
+
+ public increment() {
+ count = count + 1;
+ }
+}
+
+class ccc {
+ int dd;
+ public ccc() {
+ this.dd = 0;
+ }
+
+ public increment() {
+ dd++;
+ }
+
+ public increment(int o) {
+ dd += o;
+ }
+}
+
+class ddd extends ccc {
+
+ public ddd() {
+ this.dd = 0;
+ }
+ public increment(int u)
+ {
+ dd = u;
+ }
+}
--- /dev/null
+#128.195.180.24
+#128.195.180.21
+#128.195.180.26
+#128.195.136.162
+#128.195.136.163
+128.195.136.164
+128.195.136.165
+128.195.136.166
+128.195.136.167
+128.195.136.168
+128.195.136.169
--- /dev/null
+MAINCLASS1=Drinker
+MAINCLASS2=Simple
+SRC1=${MAINCLASS1}.java
+SRC2=${MAINCLASS2}.java
+FLAGS1= -dsm -nooptimize -recovery -debug -mainclass ${MAINCLASS1}
+FLAGS2= -dsm -nooptimize -recovery -debug -mainclass ${MAINCLASS2}
+default:
+ ../../../../buildscript ${FLAGS1} -o ${MAINCLASS1} ${SRC1}
+ ../../../../buildscript ${FLAGS2} -o ${MAINCLASS2} ${SRC2}
+drinker:
+ ../../../../buildscript ${FLAGS1} -o ${MAINCLASS1} ${SRC1}
+simple:
+ ../../../../buildscript ${FLAGS2} -o ${MAINCLASS2} ${SRC2}
+
+clean:
+ rm -rf tmpbuilddirectory
+ rm *.bin