55
edits
Changes
→Channels
let mut vec = Vec::new();
let (sendsender, receivereceiver): (Sender<i32>, Receiver<i32>) =
mpsc::channel();
for i in 0..NUM_THREADS {
// cloning the sender so it can be exclusive to the new thread
let thread_sender = sendsender.clone();
thread::spawn(move || {
for _ in 0..NUM_THREADS {
vec.push(receivereceiver.recv().unwrap());
}