final void push(ForkJoinTask<?> task) {
ForkJoinTask<?>[] a; ForkJoinPool p;
int b = base, s = top, n;
if ((a = array) != null) { // ignore if queue removed
int m = a.length - 1; // fenced write for task visibility
U.putOrderedObject(a, ((m & s) << ASHIFT) + ABASE, task);
U.putOrderedInt(this, QTOP, s + 1);
if ((n = s - b) <= 1) {
if ((p = pool) != null)
p.signalWork(p.workQueues, this);
}
else if (n >= m)
growArray();
}
}
U.putOrderedObject 和 U.putOrderedInt 设置 WorkQueue 的数组和顶部。那么为什么不直接使用 array[i]=task 和 top=s+1。我正在阅读 ForkJoinPool 的源代码并遇到了这个问题。
来自 oracle jdk 1.8(1.8.0_131) 的源代码。