Struct try_lock::TryLock

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

A light-weight lock guarded by an atomic boolean.

Most efficient when contention is low, acquiring the lock is a single atomic swap, and releasing it just 1 more atomic swap.

It is only possible to try to acquire the lock, it is not possible to wait for the lock to become ready, like with a Mutex.

Implementations§

Create a TryLock around the value.

Try to acquire the lock of this value.

If the lock is already acquired by someone else, this returns None. You can try to acquire again whenever you want, perhaps by spinning a few times, or by using some other means of notification.

Note

The default memory ordering is to use Acquire to lock, and Release to unlock. If different ordering is required, use try_lock_explicit or try_lock_explicit_unchecked.

👎Deprecated since 0.2.3: This method is actually unsafe because it unsafely allows the use of weaker memory ordering. Please use try_lock_explicit instead

Try to acquire the lock of this value using the lock and unlock orderings.

If the lock is already acquired by someone else, this returns None. You can try to acquire again whenever you want, perhaps by spinning a few times, or by using some other means of notification.

Try to acquire the lock of this value using the specified lock and unlock orderings.

If the lock is already acquired by someone else, this returns None. You can try to acquire again whenever you want, perhaps by spinning a few times, or by using some other means of notification.

Panic

This method panics if lock_order is not any of Acquire, AcqRel, and SeqCst, or unlock_order is not any of Release and SeqCst.

Try to acquire the lock of this value using the specified lock and unlock orderings without checking that the specified orderings are strong enough to be safe.

If the lock is already acquired by someone else, this returns None. You can try to acquire again whenever you want, perhaps by spinning a few times, or by using some other means of notification.

Safety

Unlike try_lock_explicit, this method is unsafe because it does not check that the given memory orderings are strong enough to prevent data race.

Take the value back out of the lock when this is the sole owner.

Trait Implementations§

Formats the value using the given formatter. Read more
Returns the “default value” for a type. 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.