#semaphore #counter #blocking #counting #extracted #atomic #documentation

std-semaphore

A counting, blocking sempahore extracted from rust 1.7.0

1 unstable release

Uses old Rust 2015

0.1.0 Jul 15, 2016

#837 in Concurrency

Download history 352/week @ 2024-06-01 270/week @ 2024-06-08 452/week @ 2024-06-15 381/week @ 2024-06-22 269/week @ 2024-06-29 406/week @ 2024-07-06 495/week @ 2024-07-13 513/week @ 2024-07-20 298/week @ 2024-07-27 491/week @ 2024-08-03 489/week @ 2024-08-10 427/week @ 2024-08-17 547/week @ 2024-08-24 571/week @ 2024-08-31 449/week @ 2024-09-07 530/week @ 2024-09-14

2,184 downloads per month
Used in 9 crates (6 directly)

MIT/Apache

8KB
118 lines

std-semaphore

Build Status

Documentation (master)

A counting, blocking semaphore extracted from rust 1.7.0.

Semaphores are a form of atomic counter where access is only granted if the counter is a positive value. Each acquisition will block the calling thread until the counter is positive, and each release will increment the counter and unblock any threads if necessary.

Usage

Add this to your Cargo.toml:

[dependencies]
std-semaphore = "0.1"

and this to your crate root:

extern crate std_semaphore;

Examples

use std_semaphore::Semaphore;

// Create a semaphore that represents 5 resources
let sem = Semaphore::new(5);

// Acquire one of the resources
sem.acquire();

// Acquire one of the resources for a limited period of time
{
    let _guard = sem.access();
    // ...
} // resources is released here

// Release our initially acquired resource
sem.release();

License

Unless otherwise noted, all code, tests, and docs are © 2014 The Rust Project Developers and dual-licensed under the Apache 2.0 and MIT licenses. See the copyright declaration at the top of src/lib.rs for more.

No runtime deps