[concurrency-interest] Why "fast path" is faster than full enq in AQS

David Holmes davidcholmes at aapt.net.au
Fri Jan 5 07:00:02 EST 2018


The fast path just does a direct enqueue to the existing tail. The enq(), in the worst case, has to initialize the queue, and in general deals with contention due to concurrent enqueue attempts.

 

The code is different now.

 

David

 

From: Concurrency-interest [mailto:concurrency-interest-bounces at cs.oswego.edu] On Behalf Of ??? via Concurrency-interest
Sent: Friday, January 5, 2018 5:34 PM
To: dholmes at ieee.org
Cc: 'Concurrency-interest' <concurrency-interest at cs.oswego.edu>
Subject: Re: [concurrency-interest] Why "fast path" is faster than full enq in AQS

 

My JDK version is 1.8

 

private Node addWaiter(Node mode) {

    Node node = new Node(Thread.currentThread(), mode);

    // Try the fast path of enq; backup to full enq on failure

    Node pred = tail;

    if (pred != null) {

        node.prev = pred;

        if (compareAndSetTail(pred, node)) {

            pred.next = node;

            return node;

        }

    }

    enq(node);

    return node;

}

On 01/5/2018 15:30, <mailto:davidcholmes at aapt.net.au> David Holmes<davidcholmes at aapt.net.au> wrote: 

What version of the code are you looking at? I can’t see anything like that in current OpenJDK sources.

 

David

 

From: Concurrency-interest [mailto:concurrency-interest-bounces at cs.oswego.edu <mailto:concurrency-interest-bounces at cs.oswego.edu> ] On Behalf Of ??? via Concurrency-interest
Sent: Friday, January 5, 2018 4:20 PM
To: concurrency-interest <concurrency-interest at cs.oswego.edu <mailto:concurrency-interest at cs.oswego.edu> >
Subject: [concurrency-interest] Why "fast path" is faster than full enq in AQS

 

Hi, everyone:

     I'm reading the source code of "AbstractQueuedSynchronizer", getting a little confused of the reason Why "fast path" is faster than full enq in the comment "Try the fast path of enq; backup to full enq on failure" .

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20180105/f7ed05fb/attachment-0001.html>


More information about the Concurrency-interest mailing list