[−][src]Trait os_sync::Semaphore
Describes Semaphore interface
This primitive provides access to single integer that can be decremented using signal and incremented using wait
Required methods
fn new(init: u32) -> Option<Self>
Creates new instance, returning None on inability to do so.
init
is initial value for the semaphore
fn wait(&self)
Decrements self, returning immediately if it was signaled.
Otherwise awaits for signal
fn try_wait(&self) -> bool
Attempts to decrement self, returning whether self was signaled or not.
Returns true
if self was signaled
Returns false
otherwise
fn wait_timeout(&self, timeout: Duration) -> bool
Attempts to decrement self within provided time, returning whether self was signaled or not.
Returns true
if self was signaled within specified timeout
Returns false
otherwise
fn post(&self) -> bool
Increments self, returning whether another thread has been woken as result.
fn signal(&self)
Increments self, waking any awaiting thread as result
Provided methods
fn lock(&self) -> SemaphoreGuard<Self>
Gets semaphore's guard, which signal on drop.
Before guard is created, function will await for semaphore to get decremented.
fn try_lock(&self) -> Option<SemaphoreGuard<Self>>
Attempts to acquire semaphore's guard, which signal on drop.
If semaphore cannot be decremented at the current moment, returns None