一定要用闭包?
感觉有点过了。
use std::thread;
use std::time::Duration;
fn main() {
let v = vec![
1,
2,
3];
let handle = thread::spawn(move ||
{
println!(
"Here's a vector: {:?}", v);
for i
in 1..
10 {
println!(
"hi number {} from the spawned thread!", i);
thread::sleep(Duration::from_millis(1));
}
});
for i
in 1..
5 {
println!(
"hi number {} from the main thread!", i);
thread::sleep(Duration::from_millis(1));
}
handle.join().unwrap();
}
转载于:https://www.cnblogs.com/aguncn/p/11441533.html
相关资源:rust-threadpool, 用于并行任务执行的非常简单的线程池.zip