From 6b4951ade670acbe3cb34b2002fbcd4b4e6a7300 Mon Sep 17 00:00:00 2001 From: Mica White Date: Fri, 8 Mar 2024 11:45:15 -0500 Subject: Replace ownership with mutable access --- examples/basic.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'examples/basic.rs') diff --git a/examples/basic.rs b/examples/basic.rs index 535b80a..8dfca84 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -1,22 +1,22 @@ use std::thread; -use happylock::mutex::Mutex; +use happylock::mutex::{Mutex, SpinLock}; use happylock::ThreadKey; const N: usize = 10; -static DATA: Mutex = Mutex::new(0); +static DATA: SpinLock = Mutex::new(0); fn main() { for _ in 0..N { thread::spawn(move || { - let key = ThreadKey::lock().unwrap(); - let mut data = DATA.lock(key); + let mut key = ThreadKey::lock().unwrap(); + let mut data = DATA.lock(&mut key); *data += 1; }); } - let key = ThreadKey::lock().unwrap(); - let data = DATA.lock(key); + let mut key = ThreadKey::lock().unwrap(); + let data = DATA.lock(&mut key); println!("{}", *data); } -- cgit v1.2.3