# HG changeset patch # User dl # Date 1448504661 28800 # Node ID 423909a8c2a6323784838f4e3f2191ccd0e3cc15 # Parent 3b7a5a01c62708bd1dafe129230931d13859d622 8143086: Document that ForkJoinWorkerThreadFactory.newThread can return null to reject request Reviewed-by: martin, psandoz, chegar, shade, plevart diff -r 3b7a5a01c627 -r 423909a8c2a6 jdk/src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java --- a/jdk/src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java Wed Nov 25 18:18:28 2015 -0800 +++ b/jdk/src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java Wed Nov 25 18:24:21 2015 -0800 @@ -703,7 +703,8 @@ * Returns a new worker thread operating in the given pool. * * @param pool the pool this thread works in - * @return the new worker thread + * @return the new worker thread, or {@code null} if the request + * to create a thread is rejected * @throws NullPointerException if the pool is null */ public ForkJoinWorkerThread newThread(ForkJoinPool pool); @@ -1053,7 +1054,7 @@ } /** - * Shared version of pop. + * Shared version of tryUnpush. */ final boolean trySharedUnpush(ForkJoinTask task) { boolean popped = false; @@ -1064,7 +1065,8 @@ ForkJoinTask t = (ForkJoinTask) U.getObject(a, offset); if (t == task && U.compareAndSwapInt(this, QLOCK, 0, 1)) { - if (U.compareAndSwapObject(a, offset, task, null)) { + if (top == s + 1 && array == a && + U.compareAndSwapObject(a, offset, task, null)) { popped = true; top = s; } @@ -1250,12 +1252,14 @@ for (CountedCompleter r = t;;) { if (r == task) { if ((mode & IS_OWNED) == 0) { - boolean popped; + boolean popped = false; if (U.compareAndSwapInt(this, QLOCK, 0, 1)) { - if (popped = + if (top == s && array == a && U.compareAndSwapObject(a, offset, - t, null)) + t, null)) { + popped = true; top = s - 1; + } U.putOrderedInt(this, QLOCK, 0); if (popped) return t;