🔄 Refactor main function to use surelock's Mutex and KeyHandle for thread-safe counter increment
This commit is contained in:
@@ -1,3 +1,11 @@
|
|||||||
|
use surelock::{key_handle::KeyHandle, mutex::Mutex};
|
||||||
|
|
||||||
fn main() {
|
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;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user