Rust 1.63 将支持 scoped thread(作用域线程)
Rust 开发团队成员介绍了一项将在 Rust 1.63 标准库添加的重要新特性:scoped thread(作用域线程)。据介绍,这是系统层级的线程,与thread::spawn()不同,scoped thread 支持线程使用局部变量,而不仅仅是静态变量。 官方示例: use std::thread; let mut a = vec![1, 2, 3]; let mut x = 0; thread::scope(|s| { s.spawn(|| { println!("hello from the first scoped thread"); // We can borrow `a` here. dbg!(&a); }); s.spawn(|| { println!("hello from the second scoped thread"); // We can even mutably borrow `x` here, // because no other threads are using it. x += a[0] + a[2...
