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

Comparing jsr166/src/test/tck/ForkJoinTask8Test.java (file contents):
Revision 1.18 by jsr166, Sun Oct 4 18:40:57 2015 UTC vs.
Revision 1.25 by dl, Sun Oct 11 19:53:59 2015 UTC

# Line 126 | Line 126 | public class ForkJoinTask8Test extends J
126  
127          {
128              Thread.currentThread().interrupt();
129 <            long t0 = System.nanoTime();
129 >            long startTime = System.nanoTime();
130              assertSame(expected, a.join());
131 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
131 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
132              Thread.interrupted();
133          }
134  
135          {
136              Thread.currentThread().interrupt();
137 <            long t0 = System.nanoTime();
137 >            long startTime = System.nanoTime();
138              a.quietlyJoin();        // should be no-op
139 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
139 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
140              Thread.interrupted();
141          }
142  
# Line 172 | Line 172 | public class ForkJoinTask8Test extends J
172          Thread.interrupted();
173  
174          {
175 <            long t0 = System.nanoTime();
175 >            long startTime = System.nanoTime();
176              a.quietlyJoin();        // should be no-op
177 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
177 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
178          }
179  
180          try {
# Line 198 | Line 198 | public class ForkJoinTask8Test extends J
198  
199      abstract static class BinaryAsyncAction extends ForkJoinTask<Void> {
200  
201 <        private BinaryAsyncAction parent;
201 >        private volatile BinaryAsyncAction parent;
202  
203 <        private BinaryAsyncAction sibling;
203 >        private volatile BinaryAsyncAction sibling;
204  
205          protected BinaryAsyncAction() {
206              setForkJoinTaskTag(INITIAL_STATE);
# Line 243 | Line 243 | public class ForkJoinTask8Test extends J
243              super.completeExceptionally(ex);
244          }
245  
246 +        public boolean cancel(boolean mayInterruptIfRunning) {
247 +            if (super.cancel(mayInterruptIfRunning)) {
248 +                completeExceptionally(new FJException());
249 +                return true;
250 +            }
251 +            return false;
252 +        }
253 +
254          public final void complete() {
255              BinaryAsyncAction a = this;
256              for (;;) {
# Line 265 | Line 273 | public class ForkJoinTask8Test extends J
273          }
274  
275          public final void completeExceptionally(Throwable ex) {
276 <            BinaryAsyncAction a = this;
269 <            while (!a.isCompletedAbnormally()) {
276 >            for (BinaryAsyncAction a = this;;) {
277                  a.completeThisExceptionally(ex);
278                  BinaryAsyncAction s = a.sibling;
279 <                if (s != null)
280 <                    s.cancel(false);
281 <                if (!a.onException() || (a = a.parent) == null)
279 >                if (s != null && !s.isDone())
280 >                    s.completeExceptionally(ex);
281 >                if ((a = a.parent) == null)
282                      break;
283              }
284          }
# Line 303 | Line 310 | public class ForkJoinTask8Test extends J
310              try {
311                  AsyncFib f = this;
312                  int n = f.number;
313 <                if (n > 1) {
314 <                    while (n > 1) {
315 <                        AsyncFib p = f;
316 <                        AsyncFib r = new AsyncFib(n - 2);
317 <                        f = new AsyncFib(--n);
318 <                        p.linkSubtasks(r, f);
312 <                        r.fork();
313 <                    }
314 <                    f.number = n;
313 >                while (n > 1) {
314 >                    AsyncFib p = f;
315 >                    AsyncFib r = new AsyncFib(n - 2);
316 >                    f = new AsyncFib(--n);
317 >                    p.linkSubtasks(r, f);
318 >                    r.fork();
319                  }
320                  f.complete();
321              }
322              catch (Throwable ex) {
323                  compareAndSetForkJoinTaskTag(INITIAL_STATE, EXCEPTION_STATE);
324              }
325 +            if (getForkJoinTaskTag() == EXCEPTION_STATE)
326 +                throw new FJException();
327              return false;
328          }
329  
# Line 339 | Line 345 | public class ForkJoinTask8Test extends J
345          }
346  
347          public final boolean exec() {
348 <            FailingAsyncFib f = this;
349 <            int n = f.number;
350 <            if (n > 1) {
348 >            try {
349 >                FailingAsyncFib f = this;
350 >                int n = f.number;
351                  while (n > 1) {
352                      FailingAsyncFib p = f;
353                      FailingAsyncFib r = new FailingAsyncFib(n - 2);
# Line 349 | Line 355 | public class ForkJoinTask8Test extends J
355                      p.linkSubtasks(r, f);
356                      r.fork();
357                  }
358 <                f.number = n;
358 >                f.complete();
359 >            }
360 >            catch (Throwable ex) {
361 >                compareAndSetForkJoinTaskTag(INITIAL_STATE, EXCEPTION_STATE);
362              }
363 <            f.complete();
363 >            if (getForkJoinTaskTag() == EXCEPTION_STATE)
364 >                throw new FJException();
365              return false;
366          }
367  
# Line 1163 | Line 1173 | public class ForkJoinTask8Test extends J
1173          final ForkJoinTask b = ForkJoinTask.adapt(awaiter(done));
1174          final ForkJoinTask c = ForkJoinTask.adapt(awaiter(done));
1175          final ForkJoinPool p = singletonPool();
1176 <        try (PoolCleaner cleaner = cleaner(p)) {
1176 >        try (PoolCleaner cleaner = cleaner(p, done)) {
1177              Thread external = new Thread(new CheckedRunnable() {
1178                  public void realRun() {
1179                      p.execute(a);
# Line 1185 | Line 1195 | public class ForkJoinTask8Test extends J
1195                      assertFalse(r.isDone());
1196                  }};
1197              p.invoke(s);
1188            done.countDown();
1198          }
1199      }
1200  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines