mainじゃなくて関数として使いたいな…
use std_semaphore::Semaphore;
use std::thread;
use std::time::Duration;
static TOTAL_SPOTS: u32 = 3;
fn main() {
let sem = Semaphore::new(TOTAL_SPOTS.try_into().unwrap());
let mut parked_cars: Vec<u32> = Vec::new();
let car: u32 = 1;
// enter
sem.acquire();
parked_cars.push(car);
thread::sleep(Duration::from_millis(500));
println!("{:?}", parked_cars);
// exit
parked_cars.clear();
sem.release();
println!("{:?}", parked_cars);
}
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.17s
Running `target/debug/parallel`
[1]
[]