std::semaphoreCounting semaphore for concurrency control.
Limit the number of concurrent actors or tasks that can access a shared resource.
import std::semaphore;
fn main() {
let sem = semaphore.new(3);
sem.acquire();
// critical section
sem.release();
sem.free();
}
newCreate a new counting semaphore with the given number of permits.
let sem = semaphore.new(5);
SemaphoreAn opaque counting semaphore handle.
Created by semaphore.new(count). Must be freed with free() when
no longer needed to avoid leaking memory.
SemaphoreMethodsMethods available on a Semaphore.
Block until a permit is available, then acquire it.
Try to acquire a permit without blocking.
Returns true if a permit was acquired, false otherwise.
Try to acquire a permit, waiting up to timeout_ms milliseconds.
Returns true if a permit was acquired before the timeout.
Release a previously acquired permit.
Return the current number of available permits.
Release the semaphore resources.