X-Git-Url: https://git.ralfj.de/rust-101.git/blobdiff_plain/c2e9145b487a8bd3d31c5a6f318c86aaf3f9d17d..3530068c5bbcbd9185757369dd23b9edb3bbc9ad:/solutions/src/counter.rs diff --git a/solutions/src/counter.rs b/solutions/src/counter.rs index 319058e..acf8293 100644 --- a/solutions/src/counter.rs +++ b/solutions/src/counter.rs @@ -1,5 +1,6 @@ use std::sync::{Arc, RwLock}; use std::thread; +use std::time::Duration; #[derive(Clone)] pub struct ConcurrentCounter(Arc>); @@ -36,7 +37,7 @@ pub fn main() { let counter1 = counter.clone(); let handle1 = thread::spawn(move || { for _ in 0..10 { - thread::sleep_ms(15); + thread::sleep(Duration::from_millis(15)); counter1.increment(2); } }); @@ -45,14 +46,14 @@ pub fn main() { let counter2 = counter.clone(); let handle2 = thread::spawn(move || { for _ in 0..10 { - thread::sleep_ms(20); + thread::sleep(Duration::from_millis(20)); counter2.increment(3); } }); // Now we want to watch the threads working on the counter. for _ in 0..50 { - thread::sleep_ms(5); + thread::sleep(Duration::from_millis(5)); println!("Current value: {}", counter.get()); }