Struct crossbeam::sync::ShardedLock

source ·
pub struct ShardedLock<T> { /* private fields */ }
Expand description

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.

Implementations§

Creates a new ShardedLock initialized with value.

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.

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§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.