Skip to content

Commit

Permalink
Merge pull request rust-lang#1903 from mo8it/threads3
Browse files Browse the repository at this point in the history
Remove unneeded Arc
  • Loading branch information
shadows-withal authored Mar 18, 2024
2 parents f3fdb07 + 71700c5 commit 9c6f56b
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions exercises/20_threads/threads3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,18 @@ impl Queue {
}

fn send_tx(q: Queue, tx: mpsc::Sender<u32>) -> () {
let qc = Arc::new(q);
let qc1 = Arc::clone(&qc);
let qc2 = Arc::clone(&qc);

thread::spawn(move || {
for val in &qc1.first_half {
for val in q.first_half {
println!("sending {:?}", val);
tx.send(*val).unwrap();
tx.send(val).unwrap();
thread::sleep(Duration::from_secs(1));
}
});

thread::spawn(move || {
for val in &qc2.second_half {
for val in q.second_half {
println!("sending {:?}", val);
tx.send(*val).unwrap();
tx.send(val).unwrap();
thread::sleep(Duration::from_secs(1));
}
});
Expand Down

0 comments on commit 9c6f56b

Please sign in to comment.