Skip to main content

Module shared

Module shared 

Source
Expand description

Cross-isolate shared mutable state: SharedValue, SharedAtom (Phase B3).

The isolate model is share-nothing for GC-heap data. But some state genuinely needs to be visible across isolates — global configuration, shared counters, published results. Phase B3 adds an explicit, honest escape hatch: shared-atom.

§Two-tier mutable references (per the ADR)

PrimitiveBackingSend?Use case
atomGcPtr<Atom> (Mutex<Value>)!Sendisolate-local, fast
shared-atomArc<SharedAtom> (ArcSwap<SharedValue>)cross-isolate, lock-free CAS

A value stored in a shared-atom must be promotable — it must be representable as a SharedValue. The promotion cost is paid once on publish; reads (deref) are an atomic load.

§SharedValue

Covers only the “plain data” subset of Value:

  • Scalars (stored inline, no allocation)
  • Strings (Arc<str>, immutable, refcounted)
  • Keywords / symbols (StaticGcPtr<T>, interned, program-lifetime)
  • Large byte buffers (Arc<[u8]>, the BEAM off-heap-binary trick)

Closures, native resources, and isolate-bound GC objects are not promotable. This restriction is enforced at publish time via promote.

Structs§

PromoteError
Returned when a Value cannot be promoted to SharedValue.
SharedAtom
A cross-isolate mutable reference backed by a lock-free ArcSwap.

Enums§

SharedValue
A Send + Sync value representation for cross-isolate sharing.

Functions§

demote
Demote a SharedValue back into an isolate-local Value.
promote
Promote a Value to a SharedValue for cross-isolate publishing.