diff options
Diffstat (limited to 'examples/basic.rs')
| -rw-r--r-- | examples/basic.rs | 12 |
1 files changed, 6 insertions, 6 deletions
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<i32> = Mutex::new(0); +static DATA: SpinLock<i32> = 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); } |
