monitor_rs

Crates.iomonitor_rs
lib.rsmonitor_rs
version0.0.1
sourcesrc
created_at2015-09-12 13:43:38.423089
updated_at2015-12-11 23:54:29.779751
descriptionMonitor synchronization construct
homepagehttps://github.com/kirillkh/monitor_rs
repositoryhttps://github.com/kirillkh/monitor_rs
max_upload_size
id3035
size15,803
Core (github:first-rust-competition:core)

documentation

README

monitor_rs

A Rust library that implements the Monitor synchronization construct.

License: MIT

Example

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.

Commit count: 16

cargo fmt