Expand description
Distributed synchronization primitives backed by fabric memory leases.
This crate provides sync primitives where holding a lock means holding a memory lease. If the holder crashes, the lease expires and the lock auto-releases. No heartbeats, no manual timeout tuning.
§Primitives
| Type | Purpose |
|---|---|
FabricMutex | Distributed mutual exclusion with RAII guard |
FabricBarrier | Multi-party phase synchronization |
FabricOnce | One-time initialization of shared state |
watch() | Single-producer multi-consumer broadcast channel |
§Memory layout
Each primitive stores a control header followed by optional data in leased
fabric memory at a configurable base_offset. The offset partitioning lets
multiple primitives coexist in the same arena without overlap.
§Quick start
use grafos_sync::{FabricMutex, FabricBarrier, FabricOnce, watch};
use grafos_std::mem::MemBuilder;
// Acquire a memory lease from the fabric
let lease = MemBuilder::new().acquire().unwrap();
// Protect a shared counter with a distributed mutex
let mtx = FabricMutex::new(lease, 0, 0u64).unwrap();
{
let mut guard = mtx.lock(1, 100).unwrap();
*guard += 1;
// guard drops here, releasing the lock
}§Crash safety
The key insight: crash = lease expires = lock auto-releases. Every
primitive wraps a grafos_std::mem::MemLease. When a node crashes
without explicitly unlocking, the fabric reclaims the lease after its
TTL expires, which implicitly releases any locks held in that memory.
Structs§
- Fabric
Barrier - Distributed barrier backed by a fabric memory lease.
- Fabric
Mutex - Distributed mutex backed by a fabric memory lease.
- Fabric
Mutex Guard - RAII guard returned by
FabricMutex::lockandFabricMutex::try_lock. - Fabric
Once - One-time initialization primitive backed by a fabric memory lease.
- Watch
Receiver - Receiving half of a fabric watch channel.
- Watch
Sender - Sending half of a fabric watch channel.
Functions§
- watch
- Create a watch channel pair (
WatchSender,WatchReceiver) backed by leased memory.