Fiber.FLS
Fiber local storage
Fiber local storage is intended for use as a low overhead storage mechanism for fiber extensions. For example, one might associate a priority value with each fiber for a scheduler that uses a priority queue or one might use FLS to store unique id values for fibers.
val create : unit -> 'a t
create ()
allocates a new key for associating values in storage associated with fibers.
â ī¸ New keys should not be created dynamically.
get_exn fiber key
returns the value associated with the key
in the storage associated with the fiber
or raises Not_set
using raise_notrace
.
â ī¸ It is only safe to call get_exn
from the fiber itself or when the fiber is known not to be running.
get fiber key ~default
returns the value associated with the key
in the storage associated with the fiber
or the default
value.
â ī¸ It is only safe to call get
from the fiber itself or when the fiber is known not to be running.
set fiber key value
sets the value
associated with the key
to the given value in the storage associated with the fiber
.
â ī¸ It is only safe to call set
from the fiber itself or when the fiber is known not to be running.
remove fiber key
removes the value, if any, associated with the key
from the storage associated with the fiber
.
â ī¸ It is only safe to call remove
from the fiber itself or when the fiber is known not to be running.
reserve fiber key
ensures that sufficient space has been allocated to associate a value with the specified key
such that a subsequent set
with the key
will not allocate.
âšī¸ This can be used to optimize the population of the FLS and to avoid performing memory allocations in critical sections.
â ī¸ It is only safe to call reserve
from the fiber itself or when the fiber is known not to be running.