Re: CompletableFuture dependent ordering

Doug Lea via Concurrency-interest <[email protected]> Tue, 5 Jan 2021 06:57:26 -0500
Newsgroups gmane.comp.java.jsr.166-concurrency
Message-ID <[email protected]>
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