**/
public void updateAge(GameMap[][] land, int maxage, int rows, int cols) {
int countTrees = 0;
+ //System.out.println("updateAge -> maxAge : "+maxage + " rows : " + rows + " cols : "+ cols);
for(int i = 0; i<rows; i++) {
for(int j = 0; j<cols; j++) {
if(land[i][j].tree != null) {
}
}
}
- /* Debugging-> System.println("Tree count= "+countTrees); */
+// System.println("Tree count= "+countTrees);
}
public static void enterBarrier(int threadid, threadinfo[] tinfo, int numthreads) {
}
boolean check = false;
atomic {
- if(tinfo[i].counter >= tinfo[threadid].counter) {
+ if(tinfo[i].status != -1) {
+ if(tinfo[i].counter >= tinfo[threadid].counter) {
+ check = true;
+ }
+ } else {
check = true;
}
}
if(!check) {
int status = Thread.getStatus(i);
if(status==-1) {//Thread is dead
+ atomic {
+ tinfo[i].status = -1;
+ }
//System.out.println("DEBUG -> Dead\n");
continue;
}
//System.out.println("i= " + i + " i's count= " + y + " threadid= " + threadid + " mycount= " + x);
- while(y!=x) {
+ while(y!=x && (Thread.getStatus(i) != -1)) {
//Wait for 100 microseconds
sleep(100);
atomic {
public class threadinfo {
int counter;
- int id;
+ int status;
public threadinfo() {
counter = 0;
+ status = 0;
}
}
//Do N rounds
//do one move per round and synchronise
for(int i = 0; i<ROUNDS; i++) {
- System.out.println("iteration= " + i);
+// System.out.println("iteration= " + i);
atomic {
doOneMove(land, gamer);
}
}
Barrier.enterBarrier(id,mytinfo,nthreads);
}
+
+ System.out.println("\n\n\nI'm done\n\n\n");
+
+ while(true) {
+ sleep(300000);
+ }
+
}
public static void main(String[] args) {