drop_guard
Use cases
Joining threads when they fall out of scope:
extern crate drop_guard;
use DropGuard;
use ;
use Duration;
Examples
Feel free to run the included examples:
Joining threads when they fall out of scope:
extern crate drop_guard;
use drop_guard::DropGuard;
use std::thread::{spawn, sleep};
use std::time::Duration;
fn main() {
// The guard must have a name. _ will drop it instantly, which would lead to unexpected results
let _g = DropGuard::new(spawn(move || {
sleep(Duration::from_secs(2));
println!("println! from thread");
})
, |join_handle| join_handle.join().unwrap());
println!("Waiting for thread ...");
}
Feel free to run the included examples:
cargo run --example rainbow
cargo run --example thread
cargo run --example threadpool