fix: revert exercise to unsolved state

This commit is contained in:
KAUSTUBHOG 2025-11-11 00:02:52 +05:30
parent 2e9462fe1a
commit 0df7d4b9dc

View File

@ -15,28 +15,20 @@ impl Queue {
} }
fn send_tx(q: Queue, tx: mpsc::Sender<u32>) { fn send_tx(q: Queue, tx: mpsc::Sender<u32>) {
// Destructure the Queue to move first_half and second_half independently // TODO: We want to send `tx` to both threads. But currently, it is moved
let Queue { // into the first thread. How could you solve this problem?
first_half,
second_half,
} = q;
// Clone the sender so both threads can send to the same receiver
let tx1 = tx.clone();
let tx2 = tx;
thread::spawn(move || { thread::spawn(move || {
for val in first_half { for val in q.first_half {
println!("Sending {val:?}"); println!("Sending {val:?}");
tx1.send(val).unwrap(); tx.send(val).unwrap();
thread::sleep(Duration::from_millis(250)); thread::sleep(Duration::from_millis(250));
} }
}); });
thread::spawn(move || { thread::spawn(move || {
for val in second_half { for val in q.second_half {
println!("Sending {val:?}"); println!("Sending {val:?}");
tx2.send(val).unwrap(); tx.send(val).unwrap();
thread::sleep(Duration::from_millis(250)); thread::sleep(Duration::from_millis(250));
} }
}); });