| Crates.io | parc |
| lib.rs | parc |
| version | 1.0.1 |
| created_at | 2019-11-05 17:21:45.357291+00 |
| updated_at | 2019-11-08 12:06:25.987014+00 |
| description | Rust crate for cancellable time based contracts in async/await |
| homepage | https://github.com/hyyking/rustracts/tree/master/parc |
| repository | https://github.com/hyyking/rustracts/tree/master/parc |
| max_upload_size | |
| id | 178346 |
| size | 20,177 |
This crate exposes ParentArc<T> which is comparable to an Arc<T> but "strong" references cannot be cloned. This allows the ParentArc<T> to lock its weak references and block until all strong references are dropped. Once it is the only reference it can be consummed safely.
This crate is compatible with #![no_std] environnement that provides an allocator.
[dependencies]
parc = {version="1", default-features=false} # for no_std
use parc::ParentArc;
use std::thread;
use std::sync;
fn main() {
let m = ParentArc::new(sync::Mutex::new(0));
let mut vh = Vec::new();
for _ in 0..10 {
let h = thread::spawn({
let weak = ParentArc::downgrade(&m);
move || loop {
match weak.upgrade() {
Some(mutex) => *mutex.lock().unwrap() += 1,
None => break,
}
}
});
vh.push(h);
}
let _: sync::Mutex<usize> = m.block_into_inner();
for h in vh {
let _ = h.join();
}
}