1075 |
|
* on failure. |
1076 |
|
*/ |
1077 |
|
private void addWorker() { |
1078 |
< |
Throwable ex = null; |
1079 |
< |
ForkJoinWorkerThread t = null; |
1078 |
> |
Throwable newThreadFailure = null; |
1079 |
> |
boolean threadStarted = false; |
1080 |
|
try { |
1081 |
< |
t = factory.newThread(this); |
1082 |
< |
} catch (Throwable e) { |
1083 |
< |
ex = e; |
1081 |
> |
ForkJoinWorkerThread t = null; |
1082 |
> |
try { |
1083 |
> |
t = factory.newThread(this); |
1084 |
> |
} catch (Throwable e) { |
1085 |
> |
newThreadFailure = e; |
1086 |
> |
} |
1087 |
> |
if (t != null) { |
1088 |
> |
t.start(); |
1089 |
> |
threadStarted = true; |
1090 |
> |
} |
1091 |
> |
} finally { |
1092 |
> |
if (!threadStarted) { |
1093 |
> |
long c; // adjust counts |
1094 |
> |
do {} while (!UNSAFE.compareAndSwapLong |
1095 |
> |
(this, ctlOffset, c = ctl, |
1096 |
> |
(((c - AC_UNIT) & AC_MASK) | |
1097 |
> |
((c - TC_UNIT) & TC_MASK) | |
1098 |
> |
(c & ~(AC_MASK|TC_MASK))))); |
1099 |
> |
// Propagate exception if originating from an external caller |
1100 |
> |
if (!tryTerminate(false) && newThreadFailure != null && |
1101 |
> |
!(Thread.currentThread() instanceof ForkJoinWorkerThread)) |
1102 |
> |
UNSAFE.throwException(newThreadFailure); |
1103 |
> |
} |
1104 |
|
} |
1085 |
– |
if (t == null) { // null or exceptional factory return |
1086 |
– |
long c; // adjust counts |
1087 |
– |
do {} while (!UNSAFE.compareAndSwapLong |
1088 |
– |
(this, ctlOffset, c = ctl, |
1089 |
– |
(((c - AC_UNIT) & AC_MASK) | |
1090 |
– |
((c - TC_UNIT) & TC_MASK) | |
1091 |
– |
(c & ~(AC_MASK|TC_MASK))))); |
1092 |
– |
// Propagate exception if originating from an external caller |
1093 |
– |
if (!tryTerminate(false) && ex != null && |
1094 |
– |
!(Thread.currentThread() instanceof ForkJoinWorkerThread)) |
1095 |
– |
UNSAFE.throwException(ex); |
1096 |
– |
} |
1097 |
– |
else |
1098 |
– |
t.start(); |
1105 |
|
} |
1106 |
|
|
1107 |
|
/** |