pub struct Semaphore { /* private fields */ }Expand description
A counting semaphore.
Implementations§
source§impl Semaphore
impl Semaphore
sourcepub fn new(value: u32) -> Self
pub fn new(value: u32) -> Self
Creates a new Semaphore with an initial value.
A Semaphore created with a value greater than 0 cannot be disposed if
it has been decremented below its original value. If there are more
successful calls to wait than signal, the system assumes the
Semaphore is still in use and will abort if it is disposed.
sourcepub fn wait_timeout(&self, timeout: Duration) -> Result<(), WaitTimeout>
pub fn wait_timeout(&self, timeout: Duration) -> Result<(), WaitTimeout>
Wait for (decrement) self until the specified timeout has elapsed.
sourcepub fn signal(&self) -> bool
pub fn signal(&self) -> bool
Signal (increment) self.
If the previous value was less than zero, this method wakes a waiting thread.
Returns true if a thread is woken or false otherwise.
sourcepub fn access(&self) -> SemaphoreGuard
pub fn access(&self) -> SemaphoreGuard
Wait to access a resource protected by self. This decrements self and returns a guard that increments when dropped.
sourcepub fn access_timeout(
&self,
timeout: Duration
) -> Result<SemaphoreGuard, WaitTimeout>
pub fn access_timeout( &self, timeout: Duration ) -> Result<SemaphoreGuard, WaitTimeout>
Wait until the specified timeout to access a resource protected by self. This decrements self and returns a guard that increments when dropped.