spincell
A small, lightweight thread-safe cell implementation targeting no_std environments.
Features
- Small and lightweight: designed to be minimal and easy to audit.
- Targets no_std environments: uses core primitives (AtomicBool, UnsafeCell, MaybeUninit).
- Provides a Lazy/Delayed initialization API similar to LazyLock.
- Uses a spinlock to implement a thread-safe cell.
Usage
Future work / TODO
- Improve TOCTOU behavior during initialization. Current try_initialize / force_initialize interactions can lead to races where a thread observes the cell as uninitialized and another thread initializes it concurrently. Possible fixes include using an atomic compare-exchange to acquire initialization rights, using Arc-based publish-swap, or employing an epoch/RCU-style reclamation mechanism.
- Support for pluggable lock implementations (a lock_api-like abstraction). Allow users to choose different locking strategies (e.g., spin vs parking vs OS mutex) for performance and platform constraints.