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.close();
}
newCreate a new counting semaphore with the given number of permits.
import std.semaphore;
fn main() {
let sem = semaphore.new(5);
}
SemaphoreSemaphoreMethodsMethods 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.