--- jsr166/src/jsr166y/ForkJoinTask.java 2011/02/22 00:39:31 1.74 +++ jsr166/src/jsr166y/ForkJoinTask.java 2011/03/15 19:47:02 1.77 @@ -1,7 +1,7 @@ /* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain + * http://creativecommons.org/publicdomain/zero/1.0/ */ package jsr166y; @@ -282,8 +282,11 @@ public abstract class ForkJoinTask im if (s == 0) UNSAFE.compareAndSwapInt(this, statusOffset, 0, SIGNAL); - else + else { wait(millis); + if (millis > 0L) + break; + } } } } @@ -381,13 +384,13 @@ public abstract class ForkJoinTask im * periods. However, since we do not know when the last joiner * completes, we must use weak references and expunge them. We do * so on each operation (hence full locking). Also, some thread in - * any ForkJoinPool will call helpExpunge when its pool becomes - * isQuiescent. + * any ForkJoinPool will call helpExpungeStaleExceptions when its + * pool becomes isQuiescent. */ static final class ExceptionNode extends WeakReference>{ final Throwable ex; ExceptionNode next; - final long thrower; + final long thrower; // use id not ref to avoid weak cycles ExceptionNode(ForkJoinTask task, Throwable ex, ExceptionNode next) { super(task, exceptionTableRefQueue); this.ex = ex; @@ -403,7 +406,7 @@ public abstract class ForkJoinTask im */ private int setExceptionalCompletion(Throwable ex) { int h = System.identityHashCode(this); - ReentrantLock lock = exceptionTableLock; + final ReentrantLock lock = exceptionTableLock; lock.lock(); try { expungeStaleExceptions(); @@ -428,7 +431,7 @@ public abstract class ForkJoinTask im */ private void clearExceptionalCompletion() { int h = System.identityHashCode(this); - ReentrantLock lock = exceptionTableLock; + final ReentrantLock lock = exceptionTableLock; lock.lock(); try { ExceptionNode[] t = exceptionTable; @@ -473,7 +476,7 @@ public abstract class ForkJoinTask im return null; int h = System.identityHashCode(this); ExceptionNode e; - ReentrantLock lock = exceptionTableLock; + final ReentrantLock lock = exceptionTableLock; lock.lock(); try { expungeStaleExceptions(); @@ -539,11 +542,11 @@ public abstract class ForkJoinTask im } /** - * If lock is available, poll any stale refs and remove them. + * If lock is available, poll stale refs and remove them. * Called from ForkJoinPool when pools become quiescent. */ static final void helpExpungeStaleExceptions() { - ReentrantLock lock = exceptionTableLock; + final ReentrantLock lock = exceptionTableLock; if (lock.tryLock()) { try { expungeStaleExceptions();