提交 dd70c1b8 编写于 作者: D dl

6871697: LinkedBlockingQueue Iterator/remove/poll race

Summary: More checks for node.next == node
Reviewed-by: martin, dholmes, chegar
上级 0936772d
......@@ -766,19 +766,21 @@ public class LinkedBlockingQueue<E> extends AbstractQueue<E>
}
/**
* Unlike other traversal methods, iterators need to handle:
* Returns the next live successor of p, or null if no such.
*
* Unlike other traversal methods, iterators need to handle both:
* - dequeued nodes (p.next == p)
* - interior removed nodes (p.item == null)
* - (possibly multiple) interior removed nodes (p.item == null)
*/
private Node<E> nextNode(Node<E> p) {
Node<E> s = p.next;
if (p == s)
return head.next;
// Skip over removed nodes.
// May be necessary if multiple interior Nodes are removed.
while (s != null && s.item == null)
s = s.next;
return s;
for (;;) {
Node<E> s = p.next;
if (s == p)
return head.next;
if (s == null || s.item != null)
return s;
p = s;
}
}
public E next() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册