File tree Expand file tree Collapse file tree 1 file changed +3
-13
lines changed
Expand file tree Collapse file tree 1 file changed +3
-13
lines changed Original file line number Diff line number Diff line change 1- // threads1.rs
2- //
3- // This program spawns multiple threads that each run for at least 250ms, and
4- // each thread returns how much time they took to complete. The program should
5- // wait until all the spawned threads have finished and should collect their
6- // return values into a vector.
7- //
8- // Execute `rustlings hint threads1` or use the `hint` watch subcommand for a
9- // hint.
10-
11- // I AM NOT DONE
12-
131use std:: thread;
142use std:: time:: { Duration , Instant } ;
153
@@ -26,7 +14,9 @@ fn main() {
2614
2715 let mut results: Vec < u128 > = vec ! [ ] ;
2816 for handle in handles {
29- // TODO: a struct is returned from thread::spawn, can you use it?
17+ // 等待线程完成并获取返回值(unwrap处理可能的JoinError)
18+ let result = handle. join ( ) . unwrap ( ) ;
19+ results. push ( result) ;
3020 }
3121
3222 if results. len ( ) != 10 {
You can’t perform that action at this time.
0 commit comments