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

Comparing jsr166/src/test/loops/CASLoops.java (file contents):
Revision 1.5 by jsr166, Tue Nov 3 01:04:02 2009 UTC vs.
Revision 1.11 by jsr166, Sat Dec 31 19:10:25 2016 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea and released to the public domain, as explained at
3 < * http://creativecommons.org/licenses/publicdomain
3 > * http://creativecommons.org/publicdomain/zero/1.0/
4   */
5  
6   /*
# Line 26 | Line 26
26   * if this program is called with (any) second argument
27   */
28  
29 <
29 > import java.util.concurrent.CyclicBarrier;
30   import java.util.concurrent.atomic.AtomicInteger;
31 import java.util.concurrent.atomic.AtomicLong;
31   import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
32 < import java.util.concurrent.*;
33 < import java.util.concurrent.locks.*;
32 > import java.util.concurrent.atomic.AtomicLong;
33 > import java.util.concurrent.locks.AbstractQueuedSynchronizer;
34  
35   public class CASLoops {
36  
# Line 46 | Line 45 | public class CASLoops {
45          if (args.length > 0)
46              maxThreads = Integer.parseInt(args[0]);
47  
48 <        loopIters = new long[maxThreads+1];
48 >        loopIters = new long[maxThreads+1];
49  
50          if (args.length > 1)
51              includeLocks = true;
# Line 115 | Line 114 | public class CASLoops {
114                  valueUpdater = AtomicIntegerFieldUpdater.newUpdater
115                  (UpdaterAtomicInteger.class, "value");
116  
118
117          UpdaterAtomicInteger() {}
118          int get() {
119              return value;
# Line 161 | Line 159 | public class CASLoops {
159          synchronized void set(int val) { value = val; }
160      }
161  
164
162      static final class LockedInteger extends AbstractQueuedSynchronizer {
163          int value;
164          LockedInteger() {}
# Line 537 | Line 534 | public class CASLoops {
534          return timer.getTime();
535      }
536  
540
537      static long runSynched(int n, long iters) throws Exception {
538          LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
539          CyclicBarrier b = new CyclicBarrier(n+1, timer);
# Line 573 | Line 569 | public class CASLoops {
569          System.out.println("\t " + secs + "s run time");
570      }
571  
576
572      static void oneRun(int i, long iters, boolean print) throws Exception {
573          if (print)
574              System.out.println("threads : " + i +
575                                 " base iters per thread per run : " +
576                                 LoopHelpers.rightJustify(loopIters[i]));
577 <        long ntime = runNonAtomic(i,  iters);
577 >        long ntime = runNonAtomic(i, iters);
578          if (print)
579              report("Base        : ", ntime, ntime, i, iters);
580          Thread.sleep(100L);
# Line 606 | Line 601 | public class CASLoops {
601              report("Synchronized: ", stime, ntime, i, iters);
602          Thread.sleep(100L);
603      }
609
610
604   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines