threads 2

This commit is contained in:
Abrar Habib 2023-04-13 11:18:03 -04:00
parent 2d8184bbcb
commit 6cc48294cb

View File

@ -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 {