summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorBotahamec <botahamec@outlook.com>2024-05-21 19:17:11 -0400
committerBotahamec <botahamec@outlook.com>2024-05-21 19:17:11 -0400
commit86610b631c20832d160c1a38181080232a05b508 (patch)
treed10eaefdf7ecaa6add29c87ed4be77e231b8bfd1 /examples
parentcf49f2900fe3c7abd1bbadacfdc745d6b5bbc235 (diff)
Sharable API
Diffstat (limited to 'examples')
-rw-r--r--examples/dining_philosophers.rs3
-rw-r--r--examples/double_mutex.rs3
2 files changed, 4 insertions, 2 deletions
diff --git a/examples/dining_philosophers.rs b/examples/dining_philosophers.rs
index 1340564..70826ba 100644
--- a/examples/dining_philosophers.rs
+++ b/examples/dining_philosophers.rs
@@ -1,5 +1,6 @@
use std::{thread, time::Duration};
+use happylock::collection::RetryingLockCollection;
use happylock::{collection::RefLockCollection, Mutex, ThreadKey};
static PHILOSOPHERS: [Philosopher; 5] = [
@@ -51,7 +52,7 @@ impl Philosopher {
// safety: no philosopher asks for the same fork twice
let forks = [&FORKS[self.left], &FORKS[self.right]];
- let forks = unsafe { RefLockCollection::new_unchecked(&forks) };
+ let forks = unsafe { RetryingLockCollection::new_unchecked(&forks) };
let forks = forks.lock(key);
println!("{} is eating...", self.name);
thread::sleep(Duration::from_secs(1));
diff --git a/examples/double_mutex.rs b/examples/double_mutex.rs
index e2b08df..e9a9c77 100644
--- a/examples/double_mutex.rs
+++ b/examples/double_mutex.rs
@@ -1,5 +1,6 @@
use std::thread;
+use happylock::collection::RetryingLockCollection;
use happylock::{collection::RefLockCollection, Mutex, ThreadKey};
const N: usize = 10;
@@ -11,7 +12,7 @@ fn main() {
for _ in 0..N {
let th = thread::spawn(move || {
let key = ThreadKey::get().unwrap();
- let lock = RefLockCollection::new(&DATA);
+ let lock = RetryingLockCollection::new_ref(&DATA);
let mut guard = lock.lock(key);
*guard.1 = (100 - *guard.0).to_string();
*guard.0 += 1;