4 releases

Uses old Rust 2015

0.1.0 Jul 3, 2016
0.0.3 Sep 12, 2015
0.0.2 Sep 12, 2015
0.0.1 Sep 12, 2015

#289 in Template engine

Download history 367/week @ 2023-10-29 325/week @ 2023-11-05 286/week @ 2023-11-12 266/week @ 2023-11-19 258/week @ 2023-11-26 305/week @ 2023-12-03 295/week @ 2023-12-10 262/week @ 2023-12-17 126/week @ 2023-12-24 108/week @ 2023-12-31 202/week @ 2024-01-07 161/week @ 2024-01-14 193/week @ 2024-01-21 167/week @ 2024-01-28 298/week @ 2024-02-04 183/week @ 2024-02-11

856 downloads per month
Used in 5 crates (3 directly)

Custom license

15KB
339 lines

monitor_rs

A convenience library that provides an easier way to use the combination of Mutex+Condvar in Rust. The concept is known as Monitor synchronization construct and is similar to Java's synchronized() statement.

License: MIT

Usage

Put this in your Cargo.toml:

[dependencies]
monitor = "0.1.0"

And this in your crate root:

extern crate monitor;

Example

extern crate monitor;

use std::time::Duration;
use std::sync::Arc;
use std::thread;
use monitor::Monitor;

fn main() {
    let mon = Arc::new(Monitor::new(false));
    {
        let mon = mon.clone();
        let _ = thread::spawn(move || {
            thread::sleep(Duration::from_millis(1000));
            
            mon.with_lock(|mut done| {     // done is a monitor::MonitorGuard<bool>
                *done = true;
                done.notify_one();
            });
        });
    }
    
    mon.with_lock(|mut done| {
        while !*done {
            done.wait();
        }
        println!("finished waiting");
    });
}

For more examples, see the tests in lib.rs.

No runtime deps