diff options
Diffstat (limited to 'exercises/20_threads')
| -rw-r--r-- | exercises/20_threads/threads1.rs | 7 | ||||
| -rw-r--r-- | exercises/20_threads/threads2.rs | 7 | ||||
| -rw-r--r-- | exercises/20_threads/threads3.rs | 40 |
3 files changed, 21 insertions, 33 deletions
diff --git a/exercises/20_threads/threads1.rs b/exercises/20_threads/threads1.rs index 80b6def..bf0b8e0 100644 --- a/exercises/20_threads/threads1.rs +++ b/exercises/20_threads/threads1.rs @@ -1,14 +1,7 @@ -// threads1.rs -// // This program spawns multiple threads that each run for at least 250ms, and // each thread returns how much time they took to complete. The program should // wait until all the spawned threads have finished and should collect their // return values into a vector. -// -// Execute `rustlings hint threads1` or use the `hint` watch subcommand for a -// hint. - -// I AM NOT DONE use std::thread; use std::time::{Duration, Instant}; diff --git a/exercises/20_threads/threads2.rs b/exercises/20_threads/threads2.rs index 60d6824..2bdeba9 100644 --- a/exercises/20_threads/threads2.rs +++ b/exercises/20_threads/threads2.rs @@ -1,13 +1,6 @@ -// threads2.rs -// // Building on the last exercise, we want all of the threads to complete their // work but this time the spawned threads need to be in charge of updating a // shared value: JobStatus.jobs_completed -// -// Execute `rustlings hint threads2` or use the `hint` watch subcommand for a -// hint. - -// I AM NOT DONE use std::sync::Arc; use std::thread; diff --git a/exercises/20_threads/threads3.rs b/exercises/20_threads/threads3.rs index acb97b4..13abc45 100644 --- a/exercises/20_threads/threads3.rs +++ b/exercises/20_threads/threads3.rs @@ -1,10 +1,3 @@ -// threads3.rs -// -// Execute `rustlings hint threads3` or use the `hint` watch subcommand for a -// hint. - -// I AM NOT DONE - use std::sync::mpsc; use std::sync::Arc; use std::thread; @@ -44,20 +37,29 @@ fn send_tx(q: Queue, tx: mpsc::Sender<u32>) -> () { }); } -#[test] fn main() { - let (tx, rx) = mpsc::channel(); - let queue = Queue::new(); - let queue_length = queue.length; + // You can optionally experiment here. +} - send_tx(queue, tx); +#[cfg(test)] +mod tests { + use super::*; - let mut total_received: u32 = 0; - for received in rx { - println!("Got: {}", received); - total_received += 1; - } + #[test] + fn threads3() { + let (tx, rx) = mpsc::channel(); + let queue = Queue::new(); + let queue_length = queue.length; - println!("total numbers received: {}", total_received); - assert_eq!(total_received, queue_length) + send_tx(queue, tx); + + let mut total_received: u32 = 0; + for received in rx { + println!("Got: {}", received); + total_received += 1; + } + + println!("total numbers received: {}", total_received); + assert_eq!(total_received, queue_length) + } } |
