ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/RLJBar.java
(Generate patch)

Comparing jsr166/src/test/loops/RLJBar.java (file contents):
Revision 1.4 by jsr166, Wed Sep 1 07:20:36 2010 UTC vs.
Revision 1.5 by jsr166, Wed Sep 1 07:47:27 2010 UTC

# Line 16 | Line 16 | class Producer extends Thread
16   {
17      //  private static Hashtable buddiesOnline = new Hashtable();
18    private static Map buddiesOnline = new ConcurrentHashMap();
19 <  public Producer (String name) { super(name); }
19 >  public Producer(String name) { super(name); }
20  
21    public void run()
22      {
23 <      Object key = null ;
23 >      Object key = null;
24        final ReentrantLock dr = RLJBar.DeathRow;
25        final ReentrantLock bar = RLJBar.bar;
26        final ReentrantLock end = RLJBar.End;
27        final Condition endCondition = RLJBar.EndCondition;
28 <      if (RLJBar.OneKey) key = new Integer(0) ;         // per-thread v. per iteration
28 >      if (RLJBar.OneKey) key = new Integer(0);         // per-thread v. per iteration
29  
30        // The barrier has a number of interesting effects:
31        // 1.     It enforces full LWP provisioning on T1.
# Line 38 | Line 38 | class Producer extends Thread
38        try {
39            bar.lock();
40            try {
41 <              ++RLJBar.nUp ;
41 >              ++RLJBar.nUp;
42                if (RLJBar.nUp == RLJBar.nThreads) {
43                    if (RLJBar.quiesce != 0) {
44 <                      RLJBar.barCondition.awaitNanos(RLJBar.quiesce * 1000000) ;
44 >                      RLJBar.barCondition.awaitNanos(RLJBar.quiesce * 1000000);
45                    }
46 <                  RLJBar.epoch = System.currentTimeMillis () ;
47 <                  RLJBar.barCondition.signalAll () ;
48 <                  //                  System.out.print ("Consensus ") ;
46 >                  RLJBar.epoch = System.currentTimeMillis();
47 >                  RLJBar.barCondition.signalAll();
48 >                  //                  System.out.print ("Consensus ");
49                }
50                if (RLJBar.UseBar) {
51                    while (RLJBar.nUp != RLJBar.nThreads) {
52 <                      RLJBar.barCondition.await () ;
52 >                      RLJBar.barCondition.await();
53                    }
54                }
55            }
# Line 57 | Line 57 | class Producer extends Thread
57                bar.unlock();
58            }
59        } catch (Exception ex) {
60 <        System.out.println ("Exception in barrier: " + ex) ;
60 >        System.out.println("Exception in barrier: " + ex);
61        }
62  
63        // Main execution time ... the code being timed ...
64        // HashTable.get() is highly contended (serial).
65        for (int loop = 1; loop < 100000 ;loop++) {
66 <        if (!RLJBar.OneKey) key = new Integer(0) ;
66 >        if (!RLJBar.OneKey) key = new Integer(0);
67          buddiesOnline.get(key);
68        }
69  
# Line 73 | Line 73 | class Producer extends Thread
73  
74        end.lock();
75        try {
76 <        ++RLJBar.nDead ;
76 >        ++RLJBar.nDead;
77          if (RLJBar.nDead == RLJBar.nUp) {
78 <            //          System.out.print((System.currentTimeMillis()-RLJBar.epoch) + " ms") ;
79 <          endCondition.signalAll() ;
78 >            //          System.out.print((System.currentTimeMillis()-RLJBar.epoch) + " ms");
79 >          endCondition.signalAll();
80          }
81        }
82        finally {
# Line 92 | Line 92 | public class RLJBar
92   {
93  
94      public static final int ITERS = 10;
95 <  public static boolean OneKey = false ;                        // alloc once or once per iteration
95 >  public static boolean OneKey = false;                        // alloc once or once per iteration
96  
97 <  public static boolean UseBar = false ;
98 <  public static int nThreads = 100 ;
99 <  public static int nUp = 0 ;
100 <  public static int nDead = 0 ;
101 <  public static ReentrantLock bar = new ReentrantLock() ;
102 <  public static Condition barCondition = bar.newCondition() ;
103 <  public static long epoch ;
104 <  public static ReentrantLock DeathRow = new ReentrantLock () ;
105 <  public static ReentrantLock End = new ReentrantLock () ;
106 <  public static int quiesce = 0 ;
97 >  public static boolean UseBar = false;
98 >  public static int nThreads = 100;
99 >  public static int nUp = 0;
100 >  public static int nDead = 0;
101 >  public static ReentrantLock bar = new ReentrantLock();
102 >  public static Condition barCondition = bar.newCondition();
103 >  public static long epoch;
104 >  public static ReentrantLock DeathRow = new ReentrantLock();
105 >  public static ReentrantLock End = new ReentrantLock();
106 >  public static int quiesce = 0;
107    public static Condition EndCondition = End.newCondition();
108  
109 <  public static void main (String[] args)    {
110 <      int argix = 0 ;
109 >  public static void main(String[] args)    {
110 >      int argix = 0;
111        if (argix < args.length && args[argix].equals("-o")) {
112 <          ++argix ;
113 <          OneKey = true ;
114 <          System.out.println ("OneKey") ;
112 >          ++argix;
113 >          OneKey = true;
114 >          System.out.println("OneKey");
115        }
116        if (argix < args.length && args[argix].equals ("-b")) {
117 <          ++argix ;
118 <          UseBar = true ;
119 <          System.out.println ("UseBar") ;
117 >          ++argix;
118 >          UseBar = true;
119 >          System.out.println("UseBar");
120        }
121        if (argix < args.length && args[argix].equals ("-q")) {
122 <          ++argix ;
122 >          ++argix;
123            if (argix < args.length) {
124 <              quiesce = Integer.parseInt (args[argix++]) ;
125 <              System.out.println ("Quiesce " + quiesce + " msecs") ;
124 >              quiesce = Integer.parseInt(args[argix++]);
125 >              System.out.println("Quiesce " + quiesce + " msecs");
126            }
127        }
128        for (int k = 0; k < ITERS; ++k)
# Line 130 | Line 130 | public class RLJBar
130    }
131  
132      public static void oneRun() {
133 <        DeathRow = new ReentrantLock () ;
134 <        End = new ReentrantLock () ;
133 >        DeathRow = new ReentrantLock();
134 >        End = new ReentrantLock();
135          EndCondition = End.newCondition();
136  
137 <        nDead = nUp = 0 ;
138 <        long cyBase = System.currentTimeMillis () ;
137 >        nDead = nUp = 0;
138 >        long cyBase = System.currentTimeMillis();
139          DeathRow.lock();
140          try {
141 <            for (int i = 1; i <= nThreads ; i++) {
141 >            for (int i = 1; i <= nThreads; i++) {
142                  new Producer("Producer" + i).start();
143              }
144              try {
145                  End.lock();
146                  try {
147                      while (nDead != nThreads)
148 <                        EndCondition.await() ;
148 >                        EndCondition.await();
149                  }
150                  finally {
151                      End.unlock();
152                  }
153              } catch (Exception ex) {
154 <                System.out.println ("Exception in End: " + ex) ;
154 >                System.out.println("Exception in End: " + ex);
155              }
156          }
157          finally {
158              DeathRow.unlock();
159          }
160 <        System.out.println ("Outer time: " + (System.currentTimeMillis()-cyBase)) ;
160 >        System.out.println("Outer time: " + (System.currentTimeMillis()-cyBase));
161  
162          // Let workers quiesce/exit.
163 <        try { Thread.sleep (1000) ; } catch (Exception ex) {} ;
163 >        try { Thread.sleep (1000); } catch (Exception ex) {};
164      }
165   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines