From: Stefan Disch Date: Sun, 6 Mar 2016 09:54:47 +0000 (+0100) Subject: Removed warning of rustc 1.7.0 complaining about deprecated usage of std::thread... X-Git-Url: https://git.ralfj.de/rust-101.git/commitdiff_plain/ab942598491747509a9586bf3c0c1c65785b9dd3?hp=fb6cc06498be64fa09f04b5ed847f1752e0eba49 Removed warning of rustc 1.7.0 complaining about deprecated usage of std::thread::sleep_ms. Now std::thread::sleep is used together with std::time::Duration::from_millis. --- diff --git a/workspace/src/part15.rs b/workspace/src/part15.rs index 1a6873e..6982579 100644 --- a/workspace/src/part15.rs +++ b/workspace/src/part15.rs @@ -3,6 +3,7 @@ use std::sync::{Arc, Mutex}; use std::thread; +use std::time::Duration; // The derived `Clone` implementation will clone the `Arc`, so all clones will actually talk about the same counter. @@ -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 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()); }