github ↗
docs menu

Module Rig.Local

#type device := t
#type 'a key

The type for keys of values of type 'a kept per device.

#val new_key : (device -> 'a) -> 'a key

new_key init is a key whose value on a device d is init d. A key is never freed, so a library must make its keys once, such as at a module's top level.

#val get : 'a key -> device -> 'a

get k d is k's value on d. The first get of k on d runs init d and stores its result, which every later get answers. A get that finds its value takes no lock and allocates nothing.

  • init d runs on the calling domain holding no lock of rig's, so it may call any of rig's functions, get of any key included.
  • Gets that race on a device with no value may each run init d. The first value stored is kept and every get answers it, so init makes values of which a spare is harmless.
  • An init that gets k on d runs a nested init, whose value is stored first, so both gets answer it.
  • If init d raises, get raises it and stores nothing.

Raises Lost if d is lost.