blob: 6016850838d3c98c290a144fe056f457acd77678 [file] [edit]
use std::thread;
use std::sync::{Arc, Mutex, Condvar};
use std::collections::VecDeque;
type Job = Box<dyn FnOnce() + Send + 'static>;
struct ThreadPool {
workers: Vec<thread::JoinHandle<()>>,
queue: Arc<()>,
}
impl ThreadPool {
fn execute<F>(&self, f: F)
where
F: FnOnce() + Send + 'static,
{
panic!()
}
}
fn main() {
let results = Arc::new(Mutex::new(Vec::new())); //~ NOTE this move could be avoided by cloning the original `Arc`, which is inexpensive
let pool = ThreadPool {
workers: vec![],
queue: Arc::new(()),
};
for i in 0..20 { //~ NOTE inside of this loop
// let results = Arc::clone(&results); // Forgot this.
pool.execute(move || { //~ ERROR E0382
//~^ NOTE value moved into closure here, in previous iteration of loop
//~| NOTE consider using `Arc::clone`
//~| HELP consider cloning the value before moving it into the closure
let mut r = results.lock().unwrap(); //~ NOTE use occurs due to use in closure
r.push(i);
});
}
}