static mut Gods: f32 = 0.0;
fn main() {
std::thread::spawn(|| loop {
unsafe {
Gods += 1.0;
}
esleep::s(1);//延时1s
});
std::thread::spawn(|| loop {
unsafe {
Gods += 0.1;
}
esleep::ms(100);//延时100ms
});
loop {
println!("{}", unsafe { Gods });
esleep::ms(200);//延时200ms
}
}
标签:全局变量,Gods,unsafe,esleep,loop,延时,多线程,Rust
From: https://www.cnblogs.com/hardfood/p/17568281.html