ConcurrentLinkedQueue 线程安全的 队列剖析 CAS 步骤剖析:
public boolean offer(E e) {
if (e == null) throw new NullPointerException();
Node<E> n = new Node<E>(e, null);
for (;;) {
// 取得列表的 尾节点
Node<E> t = tail;
// 取得列表的 尾节点 的下一个节点
Node<E> s = t.getNext();
if (t == tail) { //------------------------------a
if (s == null) { //------------------------------b
if (t.casNext(s, n)) { //------------------------------c
casTail(t, n); //------------------------------d
return true;
}
} else {
casTail(t, s); //------------------------------e
}
}
}
}public