You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And if -Dpreview_mt is in effect, the block also gets run more than once, even without the Fiber.yield.
Often, Foo.x represents some kind of cached object that might be expensive to compute, like #14891 and the Unicode data tables; if we also disregard the block's return value, then this would include the various interrupt handlers guarded by Atomic::Flags too. There should be an easier way in the standard library to ensure this block is really run exactly once, regardless of the degree of concurrent access.
Constants are one alternative, but whether they run at program startup or on first access is rather opaque, and also they are slightly broken, such as in #13054.
This could apply to class_property as well, and less likely to the instance variants getter and property.
The text was updated successfully, but these errors were encountered:
HertzDevil
changed the title
Class getters with blocks that run exactly once
Ensuring class_getter runs exactly once under concurrent access
Aug 14, 2024
Perhaps we can jerry rig an atomic compare and set on the type id? Then we'll just need an otherwise unused type to signal that someone else is already in the process of calculating.
I suppose we could force a mixed union using an appropriate type to signal work in progress?
The value of the class variable would effectively be typeof({{ yield }}) | WorkInProgress | Nil.
If the type of the block is a reference type, WorkInProgress could be a struct type and vice versa. That would mean two different signal types and select the appropriate one.
A
class_getter
with a block usually runs exactly once:However, if the current fiber is ever suspended, the block might be run multiple times:
And if
-Dpreview_mt
is in effect, the block also gets run more than once, even without theFiber.yield
.Often,
Foo.x
represents some kind of cached object that might be expensive to compute, like #14891 and the Unicode data tables; if we also disregard the block's return value, then this would include the various interrupt handlers guarded byAtomic::Flag
s too. There should be an easier way in the standard library to ensure this block is really run exactly once, regardless of the degree of concurrent access.Constants are one alternative, but whether they run at program startup or on first access is rather opaque, and also they are slightly broken, such as in #13054.
This could apply to
class_property
as well, and less likely to the instance variantsgetter
andproperty
.The text was updated successfully, but these errors were encountered: