[][src]Crate futures_semaphore

Semaphore holds a set of permits. Permits are used to synchronize access to a shared resource. Before accessing the shared resource, callers must acquire a permit from the semaphore. Once the permit is acquired, the caller then enters the critical section. When the caller is finished, they drop the permit to release it back to the semaphore.

Semaphore is futures-aware. Acquiring a Permit is an async function, which will yield to the futures executor if no permits are available and be woken up when one becomes available.

In contrast, acquiring a permit from a std::sync::Mutex + std::sync::Condvar style semaphore will block the entire OS thread, which could potentially deadlock the futures runtime if enough tasks are waiting on the semaphore.

Structs

Permit

A permit acquired from a semaphore, allowing access to a shared resource. Dropping a Permit will release it back to the semaphore.

Semaphore

A futures-aware semaphore.