Skip to content

๐Ÿ” A lightweight implementation of a Semaphore in Rust

License

Notifications You must be signed in to change notification settings

kkrypt0nn/simple-semaphore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

simple-semaphore

Discord Server Badge Docs.rs Badge Crates.io Badge CI Badge Dependency Status Badge

Last Commit Badge Conventional Commits Badge


A lightweight implementation of a Semaphore in Rust.

Getting Started

Installation

If you want to use this library for one of your projects, you can install it like any other Rust library

cargo add simple-semaphore

Example Usage

Here a basic example on how to use the crate:

use simple_semaphore;
use std::thread;
use std::{sync::Arc, time::Duration};

fn main() {
    let semaphore = simple_semaphore::Semaphore::new(2);
    for _ in 0..5 {
        let semaphore = Arc::clone(&semaphore);
        thread::spawn(move || {
            let permit = semaphore.acquire();
            thread::sleep(Duration::from_millis(500));
            drop(permit);
        });
    }
    thread::sleep(Duration::from_millis(3000));
}

License

This library was made with ๐Ÿ’œ by Krypton and is under the MIT License.

About

๐Ÿ” A lightweight implementation of a Semaphore in Rust

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Languages