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

Comparing jsr166/src/test/loops/UncheckedLockLoops.java (file contents):
Revision 1.6 by jsr166, Tue Nov 3 01:04:02 2009 UTC vs.
Revision 1.12 by jsr166, Mon Aug 10 03:13:34 2015 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6   /*
7   * @test
8   * @summary basic safety and liveness of ReentrantLocks, and other locks based on them
9   */
10  
11 + import java.util.*;
12   import java.util.concurrent.*;
13   import java.util.concurrent.locks.*;
13 import java.util.*;
14  
15   public final class UncheckedLockLoops {
16      static final LoopHelpers.SimpleRandom rng = new LoopHelpers.SimpleRandom();
# Line 49 | Line 49 | public final class UncheckedLockLoops {
49              oneTest(i, iters / i);
50              Thread.sleep(100);
51          }
52
52      }
53  
54      static void oneTest(int nthreads, int iters) throws Exception {
# Line 118 | Line 117 | public final class UncheckedLockLoops {
117              System.out.print("FairRReadWriteLock     ");
118          new FairReentrantReadWriteLockLoop().test(v, nthreads, fairIters);
119          Thread.sleep(10);
121
120      }
121  
122 <    static abstract class LockLoop implements Runnable {
122 >    abstract static class LockLoop implements Runnable {
123          int value;
124          int checkValue;
125          int iters;
# Line 201 | Line 199 | public final class UncheckedLockLoops {
199              int sum = 0;
200              int x = 0;
201              while (n-- > 0) {
202 <                synchronized(this) {
202 >                synchronized (this) {
203                      x = setValue(LoopHelpers.compute1(getValue()));
204                  }
205                  sum += LoopHelpers.compute2(x);
# Line 211 | Line 209 | public final class UncheckedLockLoops {
209      }
210  
211      private static class ReentrantLockLoop extends LockLoop {
212 <        final private ReentrantLock lock = new ReentrantLock();
212 >        private final ReentrantLock lock = new ReentrantLock();
213          final int loop(int n) {
214              final ReentrantLock lock = this.lock;
215              int sum = 0;
# Line 231 | Line 229 | public final class UncheckedLockLoops {
229      }
230  
231      private static class MutexLoop extends LockLoop {
232 <        final private Mutex lock = new Mutex();
232 >        private final Mutex lock = new Mutex();
233          final int loop(int n) {
234              final Mutex lock = this.lock;
235              int sum = 0;
# Line 251 | Line 249 | public final class UncheckedLockLoops {
249      }
250  
251      private static class LongMutexLoop extends LockLoop {
252 <        final private LongMutex lock = new LongMutex();
252 >        private final LongMutex lock = new LongMutex();
253          final int loop(int n) {
254              final LongMutex lock = this.lock;
255              int sum = 0;
# Line 271 | Line 269 | public final class UncheckedLockLoops {
269      }
270  
271      private static class FairReentrantLockLoop extends LockLoop {
272 <        final private ReentrantLock lock = new ReentrantLock(true);
272 >        private final ReentrantLock lock = new ReentrantLock(true);
273          final int loop(int n) {
274              final ReentrantLock lock = this.lock;
275              int sum = 0;
# Line 291 | Line 289 | public final class UncheckedLockLoops {
289      }
290  
291      private static class ReentrantWriteLockLoop extends LockLoop {
292 <        final private Lock lock = new ReentrantReadWriteLock().writeLock();
292 >        private final Lock lock = new ReentrantReadWriteLock().writeLock();
293          final int loop(int n) {
294              final Lock lock = this.lock;
295              int sum = 0;
# Line 331 | Line 329 | public final class UncheckedLockLoops {
329      }
330  
331      private static class SemaphoreLoop extends LockLoop {
332 <        final private Semaphore sem = new Semaphore(1, false);
332 >        private final Semaphore sem = new Semaphore(1, false);
333          final int loop(int n) {
334              final Semaphore sem = this.sem;
335              int sum = 0;
# Line 350 | Line 348 | public final class UncheckedLockLoops {
348          }
349      }
350      private static class FairSemaphoreLoop extends LockLoop {
351 <        final private Semaphore sem = new Semaphore(1, true);
351 >        private final Semaphore sem = new Semaphore(1, true);
352          final int loop(int n) {
353              final Semaphore sem = this.sem;
354              int sum = 0;
# Line 370 | Line 368 | public final class UncheckedLockLoops {
368      }
369  
370      private static class ReentrantReadWriteLockLoop extends LockLoop {
371 <        final private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
371 >        private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
372          final int loop(int n) {
373              final Lock rlock = lock.readLock();
374              final Lock wlock = lock.writeLock();
# Line 403 | Line 401 | public final class UncheckedLockLoops {
401  
402      }
403  
406
404      private static class FairReentrantReadWriteLockLoop extends LockLoop {
405 <        final private ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
405 >        private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
406          final int loop(int n) {
407              final Lock rlock = lock.readLock();
408              final Lock wlock = lock.writeLock();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines