ScopedValue: Capturing current bindings

Andrew Haley aph-open at littlepinkcloud.com
Fri Jun 2 14:00:08 UTC 2023


On 6/2/23 11:26, Robert Engels wrote:
> I think what a previous poster referred to was that a forked task had no ability to retain a scoped variable (eg hold a reference in a static).

Indeed. In a previous version of scoped values we had something like

     ScopedValue.Snapshot aSnapshot = ScopedValue.snapshot();
     aSnapshot.run(aRunnable);

but this gives client code the opportunity to run in the context of an
old snapshot, which we do not want to be possible. Even if that old
context has not yet exited.

> Although this has direct applicability in solving issues with a reusable buffer - it requires assistance from something like Rusts borrow checker so that a reference cannot be retained and only the contents copied - a signal to the developer that this is an expensive operation so do you really want to do this?
> 
> Although helpful it complicates things immensely and doesn’t feel like Java.

Which is why, I believe, it was discarded. I personally liked the snapshot
facility — I invented it! — but wiser heads prevailed.

-- 
Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671



More information about the loom-dev mailing list