ScopedValue structured forking/forwarding API
Alan Bateman
alan.bateman at oracle.com
Tue Jul 15 07:39:39 UTC 2025
On 11/07/2025 11:57, Nikita Bobko wrote:
> :
>
> Who defines the lifetime? The current stack inside Carrier.run defines
> the lifetime. Whilst the stack is alive, all so far bound ScopedValues
> remain alive. StructuredTaskScope takes advantage of this fact. Whenever
> users call StructuredTaskScope.join (and block the parent thread by
> doing that), they effectively make sure that the stack will live long
> enough, so that all ScopedValues could be safely accessed in child
> virtual threads.
>
It's the close method (not join) that is specified to not continue until
all threads forked in the scope have finished. Structure is enforced at
runtime. There is a per-Thread scope stack: open is a push, close is
pop. Same thing with ScopedValue where run (or call) does a push,
executes the ops, then pops. Code executing in a thread can't pop out of
order and can't terminate with a non-empty scope stack.
-Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20250715/e17591fc/attachment.htm>
More information about the loom-dev
mailing list