diff options
| author | Hunter Kvalevog <hunter@kvog.sh> | 2026-10-02 21:53:51 -0500 |
|---|---|---|
| committer | Hunter Kvalevog <hunter@kvog.sh> | 2026-10-02 21:53:51 -0500 |
| commit | 4dfc11d74ab02ac5765ae5d08fb750c91f4744b4 (patch) | |
| tree | 17ba62056d6b691dd0217b0e8f1b3a5826dce0f6 /rustlings/exercises/20_threads/threads1.rs | |
| parent | 02d8f1c62896576e1266553a56980eddbc2a88d7 (diff) | |
rustlings: move to rust/
Diffstat (limited to 'rustlings/exercises/20_threads/threads1.rs')
| -rw-r--r-- | rustlings/exercises/20_threads/threads1.rs | 37 |
1 files changed, 0 insertions, 37 deletions
diff --git a/rustlings/exercises/20_threads/threads1.rs b/rustlings/exercises/20_threads/threads1.rs deleted file mode 100644 index dbc64b1..0000000 --- a/rustlings/exercises/20_threads/threads1.rs +++ /dev/null @@ -1,37 +0,0 @@ -// This program spawns multiple threads that each runs for at least 250ms, and -// each thread returns how much time it took to complete. The program should -// wait until all the spawned threads have finished and should collect their -// return values into a vector. - -use std::{ - thread, - time::{Duration, Instant}, -}; - -fn main() { - let mut handles = Vec::new(); - for i in 0..10 { - let handle = thread::spawn(move || { - let start = Instant::now(); - thread::sleep(Duration::from_millis(250)); - println!("Thread {i} done"); - start.elapsed().as_millis() - }); - handles.push(handle); - } - - let mut results = Vec::new(); - for handle in handles { - // TODO: Collect the results of all threads into the `results` vector. - // Use the `JoinHandle` struct which is returned by `thread::spawn`. - } - - if results.len() != 10 { - panic!("Oh no! Some thread isn't done yet!"); - } - - println!(); - for (i, result) in results.into_iter().enumerate() { - println!("Thread {i} took {result}ms"); - } -} |