On Thu, 8 May 2025 14:27:07 GMT, kabutz <d...@openjdk.org> wrote: >> test/jdk/java/util/concurrent/tck/LinkedBlockingDequeTest.java line 1958: >> >>> 1956: q.add(four); >>> 1957: q.add(five); >>> 1958: q.add(six); >> >> Out of curiosity, how does `it.remove()` work under these conditions? > >> Out of curiosity, how does `it.remove()` work under these conditions? > > If we call it.remove() on the first element, it delegates to unlinkFirst() > (if we are using an ascending iterator), and unlinkLast (if we are using a > descending iterator). Similarly, if we call it.remove() on the last element > it will call unlinkLast() or unlinkFirst(). With unlinkFirst(), it will make > f.next = f (thus linking back to itself) and with unlinkLast(), it will make > l.prev = l. > > If we call it.remove() on a middle element, then we simply link the p.next = > n; n.prev = p; and does not do self-linking. Thus if we have an LBD with > 1,2,3,4,5 with two iterators pointing onto 3, if one of them removes it, then > the other will continue with 3 (cached), 4, 5, and it won't go back to the > beginning and see duplicate elements.
I've added a unit test for this. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/24925#discussion_r2136084498