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

Alex Otenko via Concurrency-interest <[email protected]> Sat, 15 Aug 2020 07:03:09 +0100
Newsgroups gmane.comp.java.jsr.166-concurrency
Message-ID <CANkgWKj-d8tk-DDPZ6W6SV9-JSekDEK9h7Tyj_RdLAuXiELh8g@mail.gmail.com>
If you formulate the correct state of the list after s == tail removed, you
may be able to see the difficulty with removing it.


Alex

On Sat, 15 Aug 2020, 04:15 Liu via Concurrency-interest, <
[email protected]> wrote:

>         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
>

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