Struct semaphore::Semaphore
[−]
[src]
pub struct Semaphore<T> { /* fields omitted */ }
Counting semaphore to control concurrent access to a common resource.
Methods
impl<T> Semaphore<T>
[src]
fn new(capacity: usize, resource: T) -> Self
[src]
Create a new semaphore around a resource.
The semaphore will limit the number of processes that can access the underlying resource at every point in time to the specified capacity.
fn try_access(&self) -> TryAccessResult<T>
[src]
Attempt to access the underlying resource of this semaphore.
This function will try to acquire access, and then return an RAII
guard structure which will release the access when it falls out of scope.
If the semaphore is out of capacity or shut down, a TryAccessError
will be returned.
fn shutdown(&self) -> ShutdownHandle<T>
[src]
Shut down the semaphore.
This prevents any further access from being granted to the underlying resource. As soon as the last access is released and the returned handle goes out of scope, the resource will be dropped.
Does not block until the resource is no longer in use. If you would like to do that,
you can call wait
on the returned handle.