2
请考虑下面的代码,我将每个线程追加到Vector以便在我产生每个线程后将它们连接到主线程,但是我无法在我的电话上调用iter()
JoinHandlers矢量。无法遍历Arc Mutex
我该如何去做这件事?
fn main() {
let requests = Arc::new(Mutex::new(Vec::new()));
let threads = Arc::new(Mutex::new(Vec::new()));
for _x in 0..100 {
println!("Spawning thread: {}", _x);
let mut client = Client::new();
let thread_items = requests.clone();
let handle = thread::spawn(move || {
for _y in 0..100 {
println!("Firing requests: {}", _y);
let start = time::precise_time_s();
let _res = client.get("http://jacob.uk.com")
.header(Connection::close())
.send().unwrap();
let end = time::precise_time_s();
thread_items.lock().unwrap().push((Request::new(end-start)));
}
});
threads.lock().unwrap().push((handle));
}
// src/main.rs:53:22: 53:30 error: type `alloc::arc::Arc<std::sync::mutex::Mutex<collections::vec::Vec<std::thread::JoinHandle<()>>>>` does not implement any method in scope named `unwrap`
for t in threads.iter(){
println!("Hello World");
}
}
请提供[MCVE](http://stackoverflow.com/help/mcve)。您的代码缺少关于您正在使用哪些库的所有解释,并且包含与您的问题无关的信息。 –