use std::sync::mpsc::channel;
use std::sync::Arc;
use std::thread;
use mcslock::raw::{spins::Mutex, MutexNode};
fn main() {
const N: usize = 10;
let data = Arc::new(Mutex::new(0));
let (tx, rx) = channel();
for _ in 0..N {
let (data, tx) = (data.clone(), tx.clone());
thread::spawn(move || {
let mut node = MutexNode::new();
data.lock_with_then(&mut node, |data| {
*data += 1;
if *data == N {
tx.send(()).unwrap();
}
});
let _ = data.lock_with_then(&mut node, |data| *data);
});
}
let _message = rx.recv();
let count = data.lock_then(|data| *data);
assert_eq!(count, N);
}