pub struct Semaphore { /* private fields */ }Implementations§
source§impl Semaphore
impl Semaphore
Basic semaphore implementation
§Examples
Create a semaphore with initial value 1, that is taken and then released.
let sem = Semaphore::new(1);
sem.wait();
assert_eq!(0, sem.get_current_value());
sem.release();sourcepub fn wait(&self)
pub fn wait(&self)
Acquires the semaphore or waits in order to do so until another consumer releases the resource.
sourcepub fn get_current_value(&self) -> u32
pub fn get_current_value(&self) -> u32
Get the current value of the semaphore.
The semaphore starts with an initial value, that is decremented until zero every time a wait() call is completed. On the other hand, the semaphore value increments every time a release() call is completed.
Auto Trait Implementations§
impl !Freeze for Semaphore
impl RefUnwindSafe for Semaphore
impl Send for Semaphore
impl Sync for Semaphore
impl Unpin for Semaphore
impl UnwindSafe for Semaphore
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