Skip to content

Commit 2e48846

Browse files
authored
Update threads1.rs
1 parent 50f24b9 commit 2e48846

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

exercises/threads/threads1.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
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-
131
use std::thread;
142
use 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 {

0 commit comments

Comments
 (0)