std-semaphore

Crates.iostd-semaphore
lib.rsstd-semaphore
version0.1.0
sourcesrc
created_at2016-07-15 20:26:15.016231
updated_at2016-07-15 20:26:15.016231
descriptionA counting, blocking sempahore extracted from rust 1.7.0.
homepagehttps://github.com/invenia/std-semaphore
repositoryhttps://github.com/invenia/std-semaphore
max_upload_size
id5677
size8,584
Eric Davies (iamed2)

documentation

https://invenia.github.io/std-semaphore

README

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.

Commit count: 6

cargo fmt