🔄 Refactor main function to use surelock's Mutex and KeyHandle for thread-safe counter increment

This commit is contained in:
2026-04-11 02:56:49 +08:00
parent d200db04c9
commit 35c616f223
+9 -1
View File
@@ -1,3 +1,11 @@
use surelock::{key_handle::KeyHandle, mutex::Mutex};
fn main() {
println!("Hello, world!");
let counter: Mutex<u32> = Mutex::new(0);
let mut handle = KeyHandle::claim();
handle.scope(|key| {
let (mut guard, _key) = key.lock(&counter);
*guard += 1;
});
}