[][src]Crate spin

This crate provides spin-based versions of the primitives in std::sync and std::lazy. Because synchronization is done through spinning, the primitives are suitable for use in no_std environments.

Features

  • Mutex, RwLock, Once/SyncOnceCell, and SyncLazy equivalents

  • Support for no_std environments

  • lock_api compatibility

  • Upgradeable RwLock guards

  • Guards can be sent and shared between threads

  • Guard leaking

Relationship with std::sync

While spin is not a drop-in replacement for std::sync (and should not be considered as such) an effort is made to keep this crate reasonably consistent with std::sync.

Many of the types defined in this crate have 'additional capabilities' when compared to std::sync:

Conversely, the types in this crate do not have some of the features std::sync has:

Feature flags

The crate comes with a few feature flags that you may wish to use.

  • lock_api enabled support for lock_api

  • ticket_mutex uses a ticket lock for the implementation of Mutex

  • std enables support for thread yielding instead of spinning

Re-exports

pub use barrier::Barrier;
pub use lazy::Lazy;
pub use mutex::Mutex;
pub use mutex::MutexGuard;
pub use once::Once;
pub use rw_lock::RwLock;
pub use rw_lock::RwLockReadGuard;
pub use rw_lock::RwLockWriteGuard;
pub use rw_lock::RwLockUpgradableGuard;

Modules

barrier

Synchronization primitive allowing multiple threads to synchronize the beginning of some computation.

lazy

Synchronization primitives for lazy evaluation.

mutex

Locks that have the same behaviour as a mutex.

once

Synchronization primitives for one-time evaluation.

rw_lock

A lock that provides data access to either one writer or many readers.