| Crates.io | simple-semaphore |
| lib.rs | simple-semaphore |
| version | 0.2.0 |
| created_at | 2024-10-19 18:44:02.3896+00 |
| updated_at | 2025-01-14 16:23:35.159075+00 |
| description | 🔐 A lightweight implementation of a Semaphore in Rust |
| homepage | |
| repository | https://github.com/kkrypt0nn/simple-semaphore |
| max_upload_size | |
| id | 1415640 |
| size | 17,992 |
A lightweight implementation of a Semaphore in Rust.
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
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));
}
This library was made with 💜 by Krypton and is under the MIT License.