Crate grafos_sync

Crate grafos_sync 

Source
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

TypePurpose
FabricMutexDistributed mutual exclusion with RAII guard
FabricBarrierMulti-party phase synchronization
FabricOnceOne-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§

FabricBarrier
Distributed barrier backed by a fabric memory lease.
FabricMutex
Distributed mutex backed by a fabric memory lease.
FabricMutexGuard
RAII guard returned by FabricMutex::lock and FabricMutex::try_lock.
FabricOnce
One-time initialization primitive backed by a fabric memory lease.
WatchReceiver
Receiving half of a fabric watch channel.
WatchSender
Sending half of a fabric watch channel.

Functions§

watch
Create a watch channel pair (WatchSender, WatchReceiver) backed by leased memory.