summaryrefslogtreecommitdiff
path: root/examples/basic.rs
diff options
context:
space:
mode:
authorMica White <botahamec@outlook.com>2024-03-08 11:45:15 -0500
committerMica White <botahamec@outlook.com>2024-03-08 11:45:15 -0500
commit6b4951ade670acbe3cb34b2002fbcd4b4e6a7300 (patch)
treec800e9888ba649e2cff27cc1b8ae001c3632572d /examples/basic.rs
parentcff337867884fc5d9eff80c77d41e64ee53c6115 (diff)
Replace ownership with mutable access
Diffstat (limited to 'examples/basic.rs')
-rw-r--r--examples/basic.rs12
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);
}