Update main.rs

pull/890/head
qwer252 1 week ago committed by GitHub
parent 700d36083b
commit c2ef2eb19a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,8 +1,7 @@
static mut COUNTER: u32 = 0; static mut COUNTER: u32 = 0;
/// SAFETY: Calling this from more than a single thread at a time is undefined /// SAFETY: 同时在多个线程调用这个方法是未定义的行为,所以你*必须*保证同一时间只
/// behavior, so you *must* guarantee you only call it from a single thread at /// 有一个线程在调用它。
/// a time.
unsafe fn add_to_count(inc: u32) { unsafe fn add_to_count(inc: u32) {
unsafe { unsafe {
COUNTER += inc; COUNTER += inc;
@ -11,7 +10,7 @@ unsafe fn add_to_count(inc: u32) {
fn main() { fn main() {
unsafe { unsafe {
// SAFETY: This is only called from a single thread in `main`. // SAFETY: 它只在 `main` 这一个线程被调用。
add_to_count(3); add_to_count(3);
println!("COUNTER: {}", *(&raw const COUNTER)); println!("COUNTER: {}", *(&raw const COUNTER));
} }

Loading…
Cancel
Save