Why SynchronousQueue.TransferQueue#clean() not clean the last node

Liu via Concurrency-interest <[email protected]> Sat, 15 Aug 2020 11:12:48 +0800 (GMT+08:00)
Newsgroups gmane.comp.java.jsr.166-concurrency
Message-ID <[email protected]>
        void clean(QNode pred, QNode s) {
            s.waiter = null; // forget thread
            while (pred.next == s) { 
                QNode h = head;
                QNode hn = h.next;   
                if (hn != null && hn.isCancelled()) {
                    advanceHead(h, hn);
                    continue;
                }
                QNode t = tail;      
                if (t == h)
                    return;
                QNode tn = t.next;
                if (t != tail)
                    continue;
                if (tn != null) {
                    advanceTail(t, tn);
                    continue;
                }
                if (s != t) {        // If not tail, try to unsplice
                    QNode sn = s.next;
                    if (sn == s || pred.casNext(s, sn))
                        return;
                }
                QNode dp = cleanMe;
                if (dp != null) {    
                    QNode d = dp.next;
                    QNode dn;
                    if (d == null ||               // d is gone or
                        d == dp ||                 // d is off list or
                        !d.isCancelled() ||        // d not cancelled or
                        (d != t &&                 // d not tail and
                         (dn = d.next) != null &&  //   has successor
                         dn != d &&                //   that is on list
                         dp.casNext(d, dn)))       // d unspliced
                        casCleanMe(dp, null);
                    if (dp == pred)
                        return;      
                } else if (casCleanMe(null, pred))
                    return;         
            }
        }


From above code, we can see that only if s is not tail, s will be cleaned in this invocation.
If s is tail, s will NOT be cleaned in this invocation.
Why to do this? Is there a situation we must avoid.


--------------------------------------------------------------------------------
Regards
Liu

_______________________________________________
Concurrency-interest mailing list
[email protected]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest