[][src]Struct crossbeam::sync::ShardedLock

pub struct ShardedLock<T> { /* fields omitted */ }

A scalable reader-writer lock.

This type of lock allows a number of readers or at most one writer at any point in time. The write portion of this lock typically allows modification of the underlying data (exclusive access) and the read portion of this lock typically allows for read-only access (shared access).

This reader-writer lock differs from typical implementations in that it internally creates a list of reader-writer locks called 'shards'. Shards are aligned and padded to the cache line size.

Read operations lock only one shard specific to the current thread, while write operations lock every shard in succession. This strategy makes concurrent read operations faster due to less contention, but write operations are slower due to increased amount of locking.

Methods

impl<T> ShardedLock<T>[src]

pub fn new(value: T) -> ShardedLock<T>[src]

Creates a new ShardedLock initialized with value.

pub fn read(&self) -> ShardedLockReadGuard<T>[src]

Locks with shared read access, blocking the current thread until it can be acquired.

The calling thread will be blocked until there are no more writers which hold the lock. There may be other readers currently inside the lock when this method returns. This method does not provide any guarantees with respect to the ordering of whether contentious readers or writers will acquire the lock first.

Returns an RAII guard which will drop the read access of this lock when dropped.

pub fn write(&self) -> ShardedLockWriteGuard<T>[src]

Locks with exclusive write access, blocking the current thread until it can be acquired.

This function will not return while other writers or other readers currently have access to the lock.

Returns an RAII guard which will drop the write access of this lock when dropped.

Trait Implementations

impl<T: Send + Sync> Sync for ShardedLock<T>[src]

impl<T: Send> Send for ShardedLock<T>[src]

impl<T: Debug> Debug for ShardedLock<T>[src]

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Erased for T[src]