pub struct LockSub(/* private fields */);
Available on crate feature
alloc
only.Expand description
A helper type used for coordination with the Lock
.
LockSub
is used in conjunction with a Lock
to provide a way to wait for the lock to be
released.
Implementations§
Source§impl LockSub
impl LockSub
Sourcepub fn wait(self)
pub fn wait(self)
Blocks the current thread until the associated Lock
is dropped.
§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();
Sourcepub fn wait_timeout(self, dur: Duration)
Available on crate feature std
only.
pub fn wait_timeout(self, dur: Duration)
std
only.Blocks the current thread for a specified duration or until the associated Lock
is dropped,
whichever comes first.
§Example
use utils_atomics::{Lock, lock};
use core::time::Duration;
use std::time::Instant;
let (lock, lock_sub) = lock();
let handle = std::thread::spawn(move || {
// Do some work with the shared resource
std::thread::sleep(Duration::from_secs(3));
lock.wake();
});
let start = Instant::now();
lock_sub.wait_timeout(Duration::from_secs(2));
assert!(start.elapsed() >= Duration::from_secs(2));
handle.join().unwrap();
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LockSub
impl RefUnwindSafe for LockSub
impl Sync for LockSub
impl Unpin for LockSub
impl UnwindSafe for LockSub
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