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.3 by jsr166, Thu Jan 22 19:39:18 2009 UTC vs.
Revision 1.4 by jsr166, Thu Oct 29 23:09:07 2009 UTC

# Line 12 | 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 47 | 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 58 | 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 85 | 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 106 | 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 117 | 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