adding a test case
[IRC.git] / Robust / src / Tests / STM2.java
1 /* This test case tests the thread joining for a JavaSTM library */ 
2 public class STM2 extends Thread {
3   public People[] team;
4   public STM2() {
5   }
6   public static void main(String[] st) {
7     int b = 0,c = 0;
8     int i;
9     
10     Integer age;
11     STM2 tmp;
12     STM2[] at5;
13     
14     at5 =  new STM2[4];
15     atomic {
16       for(i = 0; i < 4; i++) {
17         at5[i] = new STM2();
18         at5[i].team = new People[2];
19         at5[i].team[0] = new People();
20         at5[i].team[1] = new People();
21         age = new Integer(35);
22         at5[i].team[0].age = age;
23         at5[i].team[1].age = age;
24       }
25       b = at5[1].team[0].getAge();
26     }
27     System.printInt(b);
28     System.printString("\n");
29     atomic {
30       age = new Integer(70);
31       at5[1].team[1].age = age;
32       c = at5[1].team[1].getAge();
33     }
34     System.printInt(c);
35     System.printString("\n");
36     System.printString("Starting\n");
37     for(i = 0 ; i< 4; i++) {
38       tmp = at5[i];
39       tmp.start();
40     }
41     for(i = 0; i< 4; i++) {
42       tmp = at5[i];
43       tmp.join();
44     }
45     System.printString("Finished\n");
46   }
47   
48   public void run() {
49     int ag;
50     boolean old = false;
51     atomic {
52       ag = team[1].getAge();
53       if(ag > 65)
54         old = true;
55     }
56     if(old){
57       System.printString("Gets Pension"); 
58       System.printString("\n");
59     } else {
60       System.printString("Gets No Pension"); 
61       System.printString("\n");
62     }
63   }
64 }
65
66 public class People {
67   Integer age;
68   
69   public People() {
70   }
71   
72   public People(Integer age) {
73     this.age = age;
74   }
75   
76   public void setAge(Integer a) {
77     age = a;
78   }
79   
80   public int getAge() {
81     return age.intValue();
82   }
83   
84   public boolean isSenior() {
85     if(this.getAge() > 65)
86       return true;
87     return false;
88   }
89 }