- DLS = Domain Local Storage
- TLS = Thread Local Storage
- FLS = Fiber Local Storage
-
obtain "identity" of current fiber, e.g. checked Mutex
-
obtain cancelation status, token, and permission of current Fiber
-
store state related to current fiber efficiently
- current "scope" for structured concurrency
- more similar examples can be found (e.g. logging)
Fiber.current
in Picos obtains fiber record:
Fiber : {
mutable forbid : bool;
mutable packed : Computation.packed;
mutable fls : non_float array;
}
The fiber record itself can act as identity.
fls
array stores heterogenous values (via Obj
) like DLS/TLS and is accessed
through the fiber record.
via effect: 27.8ns
via TLS.get: 6.9ns (experiment to optimize it)
Both of the above are too slow!
As an aside, it should be possible have
TLS.get
itself taking roughly 1ns.
Even with TLS.get
hack, checked mutex is slower!
Mutex protected get
(i.e. read of ref):
checked: 58.3 ns
unchecked: 17.3 ns (could be made a bit faster with FAD)
FLS info could be stored within per fiber (or per handler) runtime data structures.
I don't (yet) have a proposal on how to do that, concerns: extensibility and modularity.
Independently developed things would ideally not clash. However, for my purposes in Picos, being able to store one word would be enough. I can then provide everything else through that.As an aside: match_with closure