No se puede obtener esta condición en el código fuente ConcurrentLinkedQueue [duplicado]
Esta pregunta ya tiene una respuesta aquí:
ConcurrentLinkedQueue Code Explanation 2 respuestasEn el código fuente de ConcurrentLinkedQueue, en eloffer
método:
public boolean offer(E e) {
checkNotNull(e);
final Node<E> newNode = new Node<E>(e);
for (Node<E> t = tail, p = t;;) {
Node<E> q = p.next;
if (q == null) {
// p is last node
if (p.casNext(null, newNode)) {
// Successful CAS is the linearization point
// for e to become an element of this queue,
// and for newNode to become "live".
if (p != t) // hop two nodes at a time
casTail(t, newNode); // Failure is OK.
return true;
}
// Lost CAS race to another thread; re-read next
}
else if (p == q)
// We have fallen off list. If tail is unchanged, it
// will also be off-list, in which case we need to
// jump to head, from which all live nodes are always
// reachable. Else the new tail is a better bet.
p = (t != (t = tail)) ? t : head;
else
// Check for tail updates after two hops.
p = (p != t && t != (t = tail)) ? t : q;
}
}
En la línea 352, existe esta condición:
p = (p != t && t != (t = tail)) ? t : q;
Sé que el código es poner p en la cola, pero ¿por qué usar un código tan complejo? y que hace(p != t && t != (t = tail))
¿media? cuál es la diferencia entret!=(t=tail))
yt!=t
? ¿Debería ser siempre falso?
¿Hay algún material que pueda explicar ConcurrentLinkedQueue claramente?