Skip to content

Commit d8d01bc

Browse files
committed
usage example
1 parent 931cbd5 commit d8d01bc

File tree

4 files changed

+392
-364
lines changed

4 files changed

+392
-364
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ license-file = "legal/mit.md"
1212

1313
keywords = [ "monitor", "synchronization" ]
1414

15-
[dependencies]
15+
[dev-dependencies]
1616
time = "0.1.32"

readme.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,32 @@ License: [MIT](https://github.com/kirillkh/monitor_rs/blob/master/legal/mit.md)
66
### Example
77
```rust
88

9-
TODO
9+
extern crate monitor_rs;
10+
11+
use monitor_rs::{Monitor, MonitorGuard};
12+
use std::sync::Arc;
13+
use std::thread;
14+
use std::time::Duration;
1015

11-
```
16+
fn main() {
17+
let mon = Arc::new(Monitor::new(false));
18+
{
19+
let mon = mon.clone();
20+
let _ = thread::spawn(move || {
21+
thread::sleep(Duration::new(1, 0));
22+
mon.with_lock(&|done: MonitorGuard<bool>| {
23+
*done = true;
24+
done.notify_one();
25+
});
26+
});
27+
}
28+
29+
mon.with_lock(&|mut done| {
30+
while !*done {
31+
done.wait();
32+
}
33+
});
34+
}
35+
```
36+
37+
For more examples, see the tests in lib.rs.

0 commit comments

Comments
 (0)