[记]Rust全局变量+多线程
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
}
}
-------------====================分割线====================-------------