https://github.com/kkrypt0nn/simple-semaphore
🔐 A lightweight implementation of a Semaphore in Rust
https://github.com/kkrypt0nn/simple-semaphore
rust rust-lang semaphore
Last synced: 3 months ago
JSON representation
🔐 A lightweight implementation of a Semaphore in Rust
- Host: GitHub
- URL: https://github.com/kkrypt0nn/simple-semaphore
- Owner: kkrypt0nn
- License: mit
- Created: 2024-10-19T18:05:05.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-09T10:50:21.000Z (about 1 year ago)
- Last Synced: 2025-11-07T07:18:00.873Z (7 months ago)
- Topics: rust, rust-lang, semaphore
- Language: Rust
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# simple-semaphore
[](https://discord.gg/xj6y5ZaTMr)
[](https://docs.rs/simple-semaphore)
[](https://crates.io/crates/simple-semaphore)
[](https://github.com/kkrypt0nn/simple-semaphore/actions)
[](https://deps.rs/repo/github/kkrypt0nn/simple-semaphore)
[](https://github.com/kkrypt0nn/simple-semaphore/commits/main)
[](https://conventionalcommits.org/en/v1.0.0/)
---
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
```shell
cargo add simple-semaphore
```
### Example Usage
Here a basic example on how to use the crate:
```rs
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](./LICENSE.md).