Crates.io | monitor_rs |
lib.rs | monitor_rs |
version | 0.0.1 |
source | src |
created_at | 2015-09-12 13:43:38.423089 |
updated_at | 2015-12-11 23:54:29.779751 |
description | Monitor synchronization construct |
homepage | https://github.com/kirillkh/monitor_rs |
repository | https://github.com/kirillkh/monitor_rs |
max_upload_size | |
id | 3035 |
size | 15,803 |
A Rust library that implements the Monitor synchronization construct.
License: MIT
extern crate monitor_rs;
use monitor_rs::{Monitor, MonitorGuard};
use std::sync::Arc;
use std::thread;
use std::time::Duration;
fn main() {
let mon = Arc::new(Monitor::new(false));
{
let mon = mon.clone();
let _ = thread::spawn(move || {
thread::sleep(Duration::new(1, 0));
mon.with_lock(&|done: MonitorGuard<bool>| {
*done = true;
done.notify_one();
});
});
}
mon.with_lock(&|mut done| {
while !*done {
done.wait();
}
});
}
For more examples, see the tests in lib.rs.