adding a test case
[IRC.git] / Robust / src / Benchmarks / Prefetch / MicroBenchmarks / Banking.java
1 public class Banking extends Thread {
2   Account myacc;
3   public Banking(Account myacc) {
4     this.myacc = myacc;
5   }
6
7   public void run() {
8     for(int i = 0;  i < 10000; i++) {
9       myacc
10
11
12
13
14   }
15
16   public static void main(String[] args) {
17     Banking[] b;
18     int[] mid = new int[2];
19         mid[0] = (128<<24)|(195<<16)|(175<<8)|79; //dw-8
20         mid[1] = (128<<24)|(195<<16)|(175<<8)|73; //dw-5
21     atomic {
22       b = global new Banking[2];
23       for(int i = 0; i < 2; i++) {
24         b[i] = global new Banking();
25         b[i].myacc = global new Account(i);
26       }
27     }
28
29     Banking tmp;
30     for(int i = 0; i <  2; i++) {
31       atomic {
32         tmp = b[i];
33       }
34       tmp.start(mid[i]);
35     }
36
37     for(int i = 0; i < 2; i++) {
38       atomic {
39         tmp = b[i];
40       }
41       tmp.join();
42     }
43   }
44 }
45
46 class Account {
47   int custid;
48   int balance;
49
50   public Account(int custid) {
51     this.custid = custid;
52     this.balance = 0;
53   }
54
55   public void deposit(int amt) {
56     balance += amt;
57   }
58
59   public void withdraw(int amt) {
60     if(amt > balance) {
61       System.printString("Amount is greater than balance\n");
62     } else {
63       balance -= amt;
64     }
65   }
66 }