问题描述
use std::thread;
const NTHREADS: u32 = 10;
// This is the `main` thread
// I have a following example:
fn main() {
// Make a vector to hold the children which are spawned.
let mut children = vec![];
for i in 0..NTHREADS {
// Spin up another thread
children.push(thread::spawn(move || {
println!("this is thread number {}",i);
}));
// should this line should cause error
println!("{}",i);
}
for child in children {
// Wait for the thread to finish. Returns a result.
let _ = child.join();
}
}
对于上面的例子,变量i
是被子线程借用的,那么为什么我们允许之后使用它?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)