113 if (!futures[i].cancel(true))
114 tooLate = true;
115 // Unbunch some of the cancels
116 if ( (i & 3) == 0)
117 Thread.sleep(1 + rnd.nextInt(5));
118 }
119
120 Object f0 = futures[0].get();
121 if (!tooLate) {
122 for (int i = 1; i < nthreads; ++i) {
123 if (!futures[i].isDone() || !futures[i].isCancelled())
124 throw new Error("Only one thread should complete");
125 }
126 }
127 else
128 System.out.print("(cancelled too late) ");
129
130 long endTime = System.nanoTime();
131 long time = endTime - timer.startTime;
132 if (print) {
133 double secs = (double)(time) / 1000000000.0;
134 System.out.println("\t " + secs + "s run time");
135 }
136
137 }
138
139 public final Object call() throws Exception {
140 barrier.await();
141 int sum = v;
142 int x = 0;
143 int n = ITERS;
144 while (n-- > 0) {
145 lock.lockInterruptibly();
146 try {
147 v = x = LoopHelpers.compute1(v);
148 }
149 finally {
150 lock.unlock();
151 }
152 sum += LoopHelpers.compute2(LoopHelpers.compute2(x));
153 }
|
113 if (!futures[i].cancel(true))
114 tooLate = true;
115 // Unbunch some of the cancels
116 if ( (i & 3) == 0)
117 Thread.sleep(1 + rnd.nextInt(5));
118 }
119
120 Object f0 = futures[0].get();
121 if (!tooLate) {
122 for (int i = 1; i < nthreads; ++i) {
123 if (!futures[i].isDone() || !futures[i].isCancelled())
124 throw new Error("Only one thread should complete");
125 }
126 }
127 else
128 System.out.print("(cancelled too late) ");
129
130 long endTime = System.nanoTime();
131 long time = endTime - timer.startTime;
132 if (print) {
133 double secs = (double)time / 1000000000.0;
134 System.out.println("\t " + secs + "s run time");
135 }
136
137 }
138
139 public final Object call() throws Exception {
140 barrier.await();
141 int sum = v;
142 int x = 0;
143 int n = ITERS;
144 while (n-- > 0) {
145 lock.lockInterruptibly();
146 try {
147 v = x = LoopHelpers.compute1(v);
148 }
149 finally {
150 lock.unlock();
151 }
152 sum += LoopHelpers.compute2(LoopHelpers.compute2(x));
153 }
|