1 public class Barrier extends Thread {
5 public Barrier(int n, threadinfo[] tinfo) {
11 ** Update the age of all trees in a given map
12 ** @param land The map to be searched
13 ** @param maxage The maxage of a tree
14 ** @param rows The number of rows in the map
15 ** @param cols The number of columns in the map
17 public void updateAge(GameMap[][] land, int maxage, int rows, int cols) {
19 for(int i = 0; i<rows; i++) {
20 for(int j = 0; j<cols; j++) {
21 if(land[i][j].tree != null) {
22 if(land[i][j].tree.getage() > maxage) {
23 land[i][j].tree = null;
25 land[i][j].tree.incrementage();
31 /* Debugging-> System.println("Tree count= "+countTrees); */
34 public static void enterBarrier(int threadid, threadinfo[] tinfo, int numthreads) {
37 tinfo[threadid].counter++;
38 x = tinfo[threadid].counter;
41 for(int i=0; i<numthreads; i++) {
45 boolean check = false;
47 if(tinfo[i].counter >= tinfo[threadid].counter) {
52 int status = Thread.getStatus(i);
53 if(status==-1) {//Thread is dead
54 //System.out.println("DEBUG -> Dead\n");
62 //System.out.println("i= " + i + " i's count= " + y + " threadid= " + threadid + " mycount= " + x);
65 //Wait for 100 microseconds
77 public class threadinfo {