pub struct Lock(/* private fields */);
Available on crate feature
alloc
only.Expand description
A synchronization primitive that can be used to coordinate threads.
Lock
is a type that represents a lock, which can be used to ensure that only one thread
can access a shared resource at a time.
§Example
use utils_atomics::{Lock, lock};
let (lock, lock_sub) = lock();
std::thread::spawn(move || {
// Do some work with the shared resource
lock.wake();
});
// Do some work with the shared resource
lock_sub.wait();
Implementations§
Source§impl Lock
impl Lock
Sourcepub unsafe fn from_raw(raw: *mut ()) -> Self
pub unsafe fn from_raw(raw: *mut ()) -> Self
Constructs a Lock
from a raw mutable pointer.
§Safety
This function is unsafe because it assumes the provided pointer is valid and points to a
Lock
.
Sourcepub fn silent_drop(self)
pub fn silent_drop(self)
Drops the Lock
without waking up the waiting threads.
This method currently leaks memory when the std
feature is disabled.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Lock
impl RefUnwindSafe for Lock
impl Send for Lock
impl Sync for Lock
impl Unpin for Lock
impl UnwindSafe for Lock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more