bau

Crates.iobau
lib.rsbau
version0.7.0
created_at2025-08-03 00:23:16.773161+00
updated_at2025-08-04 03:02:59.345325+00
descriptionFun, simple signaling library
homepage
repositoryhttps://github.com/GTLugo/bau
max_upload_size
id1779246
size25,870
Gabriel Lugo-Maldonado (GTLugo)

documentation

README

bau

A fun little signaling crate

fn main() {
  use bau::*;
  use std::{sync::Arc, thread, time::Duration};

  let resources = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
  let semaphore = Arc::new(Semaphore::new(resources));

  (0..semaphore.count() * 10)
    .map(|_| {
      let s = semaphore.clone();
      thread::spawn(move || {
        let res = s.wait().unwrap();

        // Critical section
        let _: i32 = dbg!(*res);
        thread::sleep(Duration::from_millis(rand::random_range(0..100)));

        // Call to signal upon exit
      })
    })
    .collect::<Vec<thread::JoinHandle<()>>>()
    .into_iter()
    .for_each(|h| h.join().unwrap());
}

[!NOTE] No AI-generated code.

Commit count: 0

cargo fmt