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.24 by jsr166, Sun Oct 11 15:34:06 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 318 | Line 325 | public class ForkJoinTask8Test extends J
325              catch (Throwable ex) {
326                  compareAndSetForkJoinTaskTag(INITIAL_STATE, EXCEPTION_STATE);
327              }
328 +            if (getForkJoinTaskTag() == EXCEPTION_STATE)
329 +                throw new FJException();
330              return false;
331          }
332  
# Line 339 | Line 348 | public class ForkJoinTask8Test extends J
348          }
349  
350          public final boolean exec() {
351 <            FailingAsyncFib f = this;
352 <            int n = f.number;
353 <            if (n > 1) {
354 <                while (n > 1) {
355 <                    FailingAsyncFib p = f;
356 <                    FailingAsyncFib r = new FailingAsyncFib(n - 2);
357 <                    f = new FailingAsyncFib(--n);
358 <                    p.linkSubtasks(r, f);
359 <                    r.fork();
351 >            try {
352 >                FailingAsyncFib f = this;
353 >                int n = f.number;
354 >                if (n > 1) {
355 >                    while (n > 1) {
356 >                        FailingAsyncFib p = f;
357 >                        FailingAsyncFib r = new FailingAsyncFib(n - 2);
358 >                        f = new FailingAsyncFib(--n);
359 >                        p.linkSubtasks(r, f);
360 >                        r.fork();
361 >                    }
362 >                    f.number = n;
363                  }
364 <                f.number = n;
364 >                f.complete();
365 >            }
366 >            catch (Throwable ex) {
367 >                compareAndSetForkJoinTaskTag(INITIAL_STATE, EXCEPTION_STATE);
368              }
369 <            f.complete();
369 >            if (getForkJoinTaskTag() == EXCEPTION_STATE)
370 >                throw new FJException();
371              return false;
372          }
373  
# Line 1163 | Line 1179 | public class ForkJoinTask8Test extends J
1179          final ForkJoinTask b = ForkJoinTask.adapt(awaiter(done));
1180          final ForkJoinTask c = ForkJoinTask.adapt(awaiter(done));
1181          final ForkJoinPool p = singletonPool();
1182 <        try (PoolCleaner cleaner = cleaner(p)) {
1182 >        try (PoolCleaner cleaner = cleaner(p, done)) {
1183              Thread external = new Thread(new CheckedRunnable() {
1184                  public void realRun() {
1185                      p.execute(a);
# Line 1185 | Line 1201 | public class ForkJoinTask8Test extends J
1201                      assertFalse(r.isDone());
1202                  }};
1203              p.invoke(s);
1188            done.countDown();
1204          }
1205      }
1206  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines