Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![allow(unused)]
- fn main() {
- use std::sync::{Arc, Mutex, Condvar};
- use std::thread;
- let pair = Arc::new((Mutex::new(false), Condvar::new()));
- let pair2 = pair.clone();
- // Inside of our lock, spawn a new thread, and then wait for it to start.
- thread::spawn(move|| {
- {
- let &(ref lock, ref cvar) = &*pair2;
- let mut started = lock.lock().unwrap();
- *started = true;
- // We notify the condvar that the value has changed.
- cvar.notify_one();
- println!("Notified");
- }
- thread::sleep_ms(0xffffff);
- });
- // Wait for the thread to start up.
- let &(ref lock, ref cvar) = &*pair;
- let mut started = lock.lock().unwrap();
- while !*started {
- started = cvar.wait(started).unwrap();
- }
- println!("Started");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement