Re: CompletableFuture dependent ordering

Martin Buchholz via Concurrency-interest <[email protected]> Mon, 18 Jan 2021 15:14:51 -0800
Newsgroups gmane.comp.java.jsr.166-concurrency
Message-ID <CA+kOe08qaqT2PJFgqFjrT3JNE3osU25PPVJMayAk6s8tCffC1Q@mail.gmail.com>
During my work maintaining CompletableFuture, ordering of dependent actions
was never a goal.
But efficiency was.

On Tue, Jan 5, 2021 at 4:05 AM Benjamin Manes via Concurrency-interest <
[email protected]> wrote:

> Thank you.  I recall some of those early issues so that makes sense. I
> agree no ordering should be relied upon but lacked a good explanation for
> the implementation preference.
>
> On Tue, Jan 5, 2021 at 3:59 AM Doug Lea via Concurrency-interest <
> [email protected]> wrote:
>
>> On 1/4/21 5:28 PM, Benjamin Manes via Concurrency-interest wrote:
>> >
>> > CompletableFuture maintains a Treiber stack for processing dependents,
>> > such as "thenAccept" and "whenComplete" actions. I couldn't find a
>> > previous discussion on this design decision. Can you please educate me
>> > on why a LIFO stack was preferred over a FIFO queue?
>>
>> There was some implicit discussion of this when people discovered that
>> the initial trial versions tended to blow call stacks and retain
>> unneeded heap pointers in recursive usages. As others have noted,
>> there's no guarantee about triggering order, so choosing one that tends
>> to use fewer resources (in the trampoline-like postComplete() method)
>> seems to be the best option. In some applications, the triggering order
>> can be surprising, but his would be true no matter what choice was made.
>>
>>
>> _______________________________________________
>> 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
>

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