use cond_sync::{CondSync, Other};
use std::{thread, time::Duration};
const NO_OF_THREADS: usize = 5;
#[test]
fn test() {
let cond_sync = CondSync::new(0_usize);
for i in 0..NO_OF_THREADS {
let cond_sync_t = cond_sync.clone();
thread::spawn(move || {
println!("Thread {i}: initializing ...");
cond_sync_t
.modify_and_notify(|v| *v += 1, Other::One)
.unwrap();
thread::sleep(Duration::from_millis(1)); println!("Thread {i}: work on phase 1");
});
}
cond_sync.wait_until(|v| *v == NO_OF_THREADS).unwrap();
println!("Main: All threads initialized");
thread::sleep(Duration::from_millis(100)); }