Updated solution

This commit is contained in:
gonzal06 2026-03-10 14:41:17 +01:00
parent 064f057b10
commit 87438d555f

View File

@ -17,8 +17,14 @@ impl Queue {
fn send_tx(q: Queue, tx: mpsc::Sender<u32>) {
// Clone the sender `tx` first.
let tx_clone = tx.clone();
// Defining the data in new variables.
// `q` cannot be moved simultaneously into multiple places.
let first_half = q.first_half;
let second_half = q.second_half;
thread::spawn(move || {
for val in q.first_half {
for val in first_half {
println!("Sending {val:?}");
// Then use the clone in the first thread. This means that
// `tx_clone` is moved to the first thread and `tx` to the second.
@ -28,7 +34,7 @@ fn send_tx(q: Queue, tx: mpsc::Sender<u32>) {
});
thread::spawn(move || {
for val in q.second_half {
for val in second_half {
println!("Sending {val:?}");
tx.send(val).unwrap();
thread::sleep(Duration::from_millis(250));