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

Comparing jsr166/src/test/loops/CancelledLockLoops.java (file contents):
Revision 1.1 by dl, Mon May 2 19:19:38 2005 UTC vs.
Revision 1.4 by jsr166, Thu Oct 29 23:09:07 2009 UTC

# Line 1 | Line 1
1   /*
2 * @test
3 * @summary tests lockInterruptibly
4 * Checks for responsiveness of locks to interrupts. Runs under that
5 * assumption that ITERS_VALUE computations require more than TIMEOUT
6 * msecs to complete.
7 */
8 /*
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/licenses/publicdomain
5   */
6  
7   import java.util.concurrent.*;
# Line 19 | Line 12 | public final class CancelledLockLoops {
12      static final Random rng = new Random();
13      static boolean print = false;
14      static final int ITERS = 10000000;
15 <    static final long TIMEOUT = 100;
15 >    static final long TIMEOUT = 100;
16  
17      public static void main(String[] args) throws Exception {
18          int maxThreads = 100;
19 <        if (args.length > 0)
19 >        if (args.length > 0)
20              maxThreads = Integer.parseInt(args[0]);
21  
22          print = true;
# Line 54 | Line 47 | public final class CancelledLockLoops {
47  
48          final void test() throws Exception {
49              Thread[] threads = new Thread[nthreads];
50 <            for (int i = 0; i < threads.length; ++i)
50 >            for (int i = 0; i < threads.length; ++i)
51                  threads[i] = new Thread(this);
52 <            for (int i = 0; i < threads.length; ++i)
52 >            for (int i = 0; i < threads.length; ++i)
53                  threads[i].start();
54              Thread[] cancels = (Thread[]) (threads.clone());
55              Collections.shuffle(Arrays.asList(cancels), rng);
# Line 65 | Line 58 | public final class CancelledLockLoops {
58              for (int i = 0; i < cancels.length-2; ++i) {
59                  cancels[i].interrupt();
60                  // make sure all OK even when cancellations spaced out
61 <                if ( (i & 3) == 0)
61 >                if ( (i & 3) == 0)
62                      Thread.sleep(1 + rng.nextInt(10));
63              }
64              barrier.await();
# Line 83 | Line 76 | public final class CancelledLockLoops {
76              finally {
77                  lock.unlock();
78              }
79 <            if (completed != 2)
79 >            if (c != 2)
80                  throw new Error("Completed != 2");
81              int r = result;
82              if (r == 0) // avoid overoptimization
# Line 92 | Line 85 | public final class CancelledLockLoops {
85  
86          public final void run() {
87              try {
88 <                barrier.await();
88 >                barrier.await();
89                  int sum = v;
90                  int x = 0;
91                  int n = ITERS;
# Line 113 | Line 106 | public final class CancelledLockLoops {
106                      sum += LoopHelpers.compute2(x);
107                  } while (n-- > 0);
108                  if (n <= 0) {
109 <                    lock.lock();
109 >                    lock.lock();
110                      try {
111                          ++completed;
112                      }
# Line 124 | Line 117 | public final class CancelledLockLoops {
117                  barrier.await();
118                  result += sum;
119              }
120 <            catch (Exception ex) {
120 >            catch (Exception ex) {
121                  //                ex.printStackTrace();
122 <                return;
122 >                return;
123              }
124          }
125      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines