Created
June 16, 2016 08:25
-
-
Save blippy/3c3bf87596e9151c6a74bb28b6c5ce01 to your computer and use it in GitHub Desktop.
Simple threads in rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //#![feature(old_io)] | |
| use std::thread; | |
| use std::old_io::timer; | |
| use std::time::duration::Duration; | |
| fn main() { | |
| let vin = vec![1.4f64, 1.2f64, 1.5f64]; | |
| let mut guards = Vec::with_capacity(3); | |
| for i in 0..3 { | |
| let inval = vin[i]; | |
| guards.push(thread::scoped( move || { | |
| let ms = (1000.0f64 * inval) as i64; | |
| let d = Duration::milliseconds(ms); | |
| timer::sleep(d); | |
| println!("Waited {}", inval); | |
| 10.0f64 + inval | |
| })); | |
| } | |
| let mut answers = Vec::with_capacity(3); | |
| for guard in guards { | |
| let answer = guard.join(); | |
| answers.push(answer); | |
| //println!("{}", answer); | |
| }; | |
| for ans in answers { println!("{}", ans) } ; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Discussion: http://stackoverflow.com/questions/28896850/why-doesnt-this-compile-use-of-undeclared-type-name-threadscoped