mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-11 21:29:18 +00:00
threads 2
This commit is contained in:
parent
2d8184bbcb
commit
6cc48294cb
@ -6,7 +6,7 @@
|
|||||||
// The program should wait until all the spawned threads have finished and
|
// The program should wait until all the spawned threads have finished and
|
||||||
// should collect their return values into a vector.
|
// should collect their return values into a vector.
|
||||||
|
|
||||||
// I AM NOT DONE
|
//use handle.join.unwrap(). .join() stops the thread from executing, and then unwrap to collect any errors.
|
||||||
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
@ -25,6 +25,7 @@ fn main() {
|
|||||||
let mut results: Vec<u128> = vec![];
|
let mut results: Vec<u128> = vec![];
|
||||||
for handle in handles {
|
for handle in handles {
|
||||||
// TODO: a struct is returned from thread::spawn, can you use it?
|
// TODO: a struct is returned from thread::spawn, can you use it?
|
||||||
|
results.push(handle.join().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
if results.len() != 10 {
|
if results.len() != 10 {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user