use std::sync::{Arc, Mutex};
use std::thread;
pub fn send_some_data(a: i64) {
let mut int = 1;
let arc = Arc::new(Mutex::new(int));
let mut handles = vec![];
for i in 0..a {
let arc_clone = Arc::clone(&arc);
let handle = thread::spawn(move ||
{
let mut val= arc_clone.lock().unwrap();
(*val) += 1;
}
);
handles.push(handle);
}
for handle in handles.iter()
{
handle.join();
^^^^^^ move occurs because `*handle` has type `std::thread::JoinHandle<()>`, which does not implement the `Copy` trait
}
}
Why? I mean, I can see that compiler is trying to explain, but none the less... If somebody could explain that to me in more digestible form. And how to fix that?
Thanks