1   /*
2    * Copyright (c) 2006-07, The Trustees of Stanford University.  All
3    * rights reserved.
4    * Licensed under the terms of the GNU GPL; see COPYING for details.
5    */
6   package test;
7   
8   /**
9    * @author Mayur Naik (mhn@cs.stanford.edu)
10   */
11  public class T extends java.lang.Thread {
12      public static void main(String[] a) {
13          B b1 = new B();
14          B b2 = new B();
15          for (int i = 0; i < 10; i++) {
16              T t = new T(b1, b2);
17              t.start();
18          }
19          for (int i = 0; i < 10; i++) {
20              b1.get();
21              synchronized (b2) {
22                  b2.set(i);
23              }
24          }
25      }
26      private B f1, f2;
27      public T(B b1, B b2) {
28          this.f1 = b1;
29          this.f2 = b2;
30      }
31      public void run() {
32          B b1 = this.f1;
33          B b2 = this.f2;
34          int i;
35          synchronized (b2) {
36              i = b2.get();
37          }
38          b1.set(i);
39      }
40  }
41