/** * Tries to create and start a worker; minimally rolls back counts * on failure. */ private void addWorker() { Throwable ex = null; ForkJoinWorkerThread t = null; try { t = factory.newThread(this); } catch (Throwable e) { ex = e; } if (t == null) { // null or exceptional factory return long c; // adjust counts do {} while (!UNSAFE.compareAndSwapLong (this, ctlOffset, c = ctl, (((c - AC_UNIT) & AC_MASK) | ((c - TC_UNIT) & TC_MASK) | (c & ~(AC_MASK|TC_MASK))))); // Propagate exception if originating from an external caller if (!tryTerminate(false) && ex != null && !(Thread.currentThread() instanceof ForkJoinWorkerThread)) UNSAFE.throwException(ex); } else t.start(); }
/** * Tries to create and start a worker */ private void addWorker() { Throwable ex = null; ForkJoinWorkerThread wt = null; try { if ((wt = factory.newThread(this)) != null) { wt.start(); return; } } catch (Throwable e) { ex = e; } deregisterWorker(wt, ex); // adjust counts etc on failure }