ScopedValue structured forking/forwarding API
Alan Bateman
alan.bateman at oracle.com
Wed Jul 9 08:58:56 UTC 2025
(Your mail appears to be from June 18 but seems to have only been
delivered to loom-dev on July 7).
On 18/06/2025 18:05, Nikita Bobko wrote:
> :
>
> ## Use cases
>
> *Use case 1.* The API would be useful for any third-party libraries
> that implement structured concurrency. kotlinx.coroutines is an
> example of such a library.
An initial question for you: Would I correct to say that the
currentThread may change across suspension points when using these
coroutines? Just asking as it isn't immediately clear if these
coroutines are compatible with ThreadLocals and other APIs/features that
depend on Thread identity.
In any case, the summary is that scoped values can only be safely
inherited into "child threads" in structured contexts. Inheritance is
one of the privileged operations and primitives that are needed to
support structured use. Right now the only API exposed that uses this
is StructuredTaskScope (STS). We need a lot more feedback and real world
usage before re-visiting the lower level construct that allows other API
be developed.
There has been some experiments with inheriting into "child tasks",
which I suspect is closer to what you are asking for. In particular
there was initial interest into inheriting into the tasks supporting the
stages of a parallel stream pipeline. The main challenges with the
experiments were in the areas of performance (esp. CountedCompleter) and
reliable recovery (e.g. StackOverflowError). These experiments are
parked right now. I read your mail as looking to reboot these explorations.
-Alan
More information about the loom-dev
mailing list