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

Comparing jsr166/src/test/loops/LockLoops.java (file contents):
Revision 1.14 by jsr166, Wed Jun 8 20:42:12 2016 UTC vs.
Revision 1.15 by jsr166, Thu Jun 9 15:28:19 2016 UTC

# Line 3 | Line 3
3   * Expert Group and released to the public domain, as explained at
4   * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6 +
7   /*
8 < * A simple test program. Feel free to play.
8 > * Simple benchmark comparing various locking techniques.
9   */
10  
11   import java.util.*;
# Line 91 | Line 92 | public final class LockLoops {
92              Thread.sleep(10);
93  
94              if (print)
95 +                System.out.print("ReentrantReadLock    ");
96 +            new ReentrantReadLockLoop().test(v, nthreads, iters);
97 +            Thread.sleep(10);
98 +
99 +            if (print)
100                  System.out.print("ReentrantReadWriteLock");
101              new ReentrantReadWriteLockLoop().test(v, nthreads, iters);
102              Thread.sleep(10);
# Line 270 | Line 276 | public final class LockLoops {
276          final int loop(int n) {
277              int sum = 0;
278              while (n-- > 0) {
279 +                lock.lock();
280 +                try {
281 +                    v = LoopHelpers.compute1(v);
282 +                }
283 +                finally {
284 +                    lock.unlock();
285 +                }
286 +                sum += LoopHelpers.compute2(v);
287 +            }
288 +            return sum;
289 +        }
290 +    }
291 +
292 +    private static class ReentrantReadLockLoop extends LockLoop {
293 +        private final Lock lock = new ReentrantReadWriteLock().readLock();
294 +        final int loop(int n) {
295 +            int sum = 0;
296 +            while (n-- > 0) {
297                  lock.lock();
298                  try {
299                      v = LoopHelpers.compute1(v);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines