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

Comparing jsr166/src/test/loops/SimpleLoops.java (file contents):
Revision 1.1 by dl, Mon May 2 19:19:38 2005 UTC vs.
Revision 1.5 by jsr166, Tue Mar 15 19:47:06 2011 UTC

# Line 1 | Line 1
1   /*
2 * @test
3 * @synopsis multiple threads using a single lock
4 */
5 /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3 < * Expert Group and released to the public domain. Use, modify, and
4 < * redistribute this code in any way without acknowledgement.
3 > * Expert Group and released to the public domain, as explained at
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
10
6   import java.util.concurrent.*;
7   import java.util.concurrent.locks.*;
8   import java.util.*;
# Line 20 | Line 15 | public final class SimpleLoops {
15  
16      public static void main(String[] args) throws Exception {
17          int maxThreads = 100;
18 <        if (args.length > 0)
18 >        if (args.length > 0)
19              maxThreads = Integer.parseInt(args[0]);
20  
21          print = true;
# Line 33 | Line 28 | public final class SimpleLoops {
28              if (i == k) {
29                  k = i << 1;
30                  i = i + (i >>> 1);
31 <            }
32 <            else
31 >            }
32 >            else
33                  i = k;
34          }
35          pool.shutdown();
# Line 53 | Line 48 | public final class SimpleLoops {
48          }
49  
50          final void test() throws Exception {
51 <            for (int i = 0; i < nthreads; ++i)
51 >            for (int i = 0; i < nthreads; ++i)
52                  pool.execute(this);
53              barrier.await();
54              barrier.await();
55              if (print) {
56                  long time = timer.getTime();
57 <                long tpi = time / ((long)iters * nthreads);
57 >                long tpi = time / ((long) iters * nthreads);
58                  System.out.print("\t" + LoopHelpers.rightJustify(tpi) + " ns per lock");
59 <                double secs = (double)(time) / 1000000000.0;
59 >                double secs = (double) time / 1000000000.0;
60                  System.out.println("\t " + secs + "s run time");
61              }
62  
# Line 72 | Line 67 | public final class SimpleLoops {
67  
68          public final void run() {
69              try {
70 <                barrier.await();
70 >                barrier.await();
71                  int sum = v + 1;
72                  int x = 0;
73                  int n = iters;
# Line 89 | Line 84 | public final class SimpleLoops {
84                          ++readBarrier;
85                      for (int l = x & 7; l > 0; --l)
86                          sum += LoopHelpers.compute1(sum);
87 <                }
87 >                }
88                  barrier.await();
89                  result += sum;
90              }
91 <            catch (Exception ie) {
92 <                return;
91 >            catch (Exception ie) {
92 >                return;
93              }
94          }
95      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines