Module std::semaphore

Counting semaphore for concurrency control.

Limit the number of concurrent actors or tasks that can access a shared resource.

Examples

import std::semaphore;

fn main() {
    let sem = semaphore.new(3);
    sem.acquire();
    // critical section
    sem.release();
    sem.free();
}

Contents

Functions

Function new

pub fn new(count: i32) -> Semaphore

Create a new counting semaphore with the given number of permits.

Examples

let sem = semaphore.new(5);

Types

Struct Semaphore

An opaque counting semaphore handle.

Created by semaphore.new(count). Must be freed with free() when no longer needed to avoid leaking memory.

Traits

Trait SemaphoreMethods

Methods available on a Semaphore.

Methods

fn acquire(self: Semaphore) fn try_acquire(self: Semaphore) -> bool fn acquire_timeout(self: Semaphore, timeout_ms: i64) -> bool fn release(self: Semaphore) fn count(self: Semaphore) -> i32 fn free(self: Semaphore)