File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed
Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change 33// Execute `rustlings hint threads3` or use the `hint` watch subcommand for a
44// hint.
55
6- // I AM NOT DONE
7-
86use std:: sync:: mpsc;
97use std:: sync:: Arc ;
108use std:: thread;
@@ -27,25 +25,29 @@ impl Queue {
2725}
2826
2927fn 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
5153fn main ( ) {
You can’t perform that action at this time.
0 commit comments