Once 的使用
#455
Replies: 1 comment
-
非常棒,宝贵的建议值得以一个 pr 来收尾,欢迎提交 :) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
我本地使用的是 Rust 1.57.0,看到 《Rust圣经》中多线程并发-使用多线程这个章节的 "[只被调用一次的函数]"时,发现例子跑不通,根据错误提示改成了如下代码:
use std::sync::Once;
use std::thread;
static mut VAL: usize = 0;
static INIT: Once= Once::new();
fn main() {
let handle1 = thread::spawn(move || {
INIT.call_once(|| {
unsafe {
VAL = 1;
}
});
});
}
就可以了。这个看下要不要后续补充到文档中
Beta Was this translation helpful? Give feedback.
All reactions