Skip to content

Commit 21cab52

Browse files
author
build
committed
feat:update
1 parent 8e01bb9 commit 21cab52

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

exercises/threads/threads3.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// Execute `rustlings hint threads3` or use the `hint` watch subcommand for a
44
// hint.
55

6-
// I AM NOT DONE
7-
86
use std::sync::mpsc;
97
use std::sync::Arc;
108
use std::thread;
@@ -27,25 +25,29 @@ impl Queue {
2725
}
2826

2927
fn send_tx(q: Queue, tx: mpsc::Sender<u32>) -> () {
28+
let tx1 = tx.clone();
29+
let tx2 = tx.clone();
3030
let qc = Arc::new(q);
3131
let qc1 = Arc::clone(&qc);
3232
let qc2 = Arc::clone(&qc);
3333

34-
thread::spawn(move || {
34+
let handler1 = thread::spawn(move || {
3535
for val in &qc1.first_half {
3636
println!("sending {:?}", val);
37-
tx.send(*val).unwrap();
37+
tx1.send(*val).unwrap();
3838
thread::sleep(Duration::from_secs(1));
3939
}
4040
});
4141

42-
thread::spawn(move || {
42+
let handler2 = thread::spawn(move || {
4343
for val in &qc2.second_half {
4444
println!("sending {:?}", val);
45-
tx.send(*val).unwrap();
45+
tx2.send(*val).unwrap();
4646
thread::sleep(Duration::from_secs(1));
4747
}
4848
});
49+
handler1.join().unwrap();
50+
handler2.join().unwrap();
4951
}
5052

5153
fn main() {

0 commit comments

Comments
 (0)