summaryrefslogtreecommitdiff
path: root/examples/fibonacci.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/fibonacci.rs')
-rw-r--r--examples/fibonacci.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/examples/fibonacci.rs b/examples/fibonacci.rs
index d43b01c..869ef71 100644
--- a/examples/fibonacci.rs
+++ b/examples/fibonacci.rs
@@ -1,4 +1,4 @@
-use happylock::{LockCollection, Mutex, ThreadKey};
+use happylock::{collection, LockCollection, Mutex, ThreadKey};
use std::thread;
const N: usize = 36;
@@ -6,19 +6,25 @@ const N: usize = 36;
static DATA: [Mutex<i32>; 2] = [Mutex::new(0), Mutex::new(1)];
fn main() {
+ let mut threads = Vec::new();
for _ in 0..N {
- thread::spawn(move || {
+ let th = thread::spawn(move || {
let key = ThreadKey::get().unwrap();
// a reference to a type that implements `OwnedLockable` will never
// contain duplicates, so no duplicate checking is needed.
- let collection = LockCollection::new_ref(&DATA);
+ let collection = collection::RetryingLockCollection::new_ref(&DATA);
let mut guard = collection.lock(key);
let x = *guard[1];
*guard[1] += *guard[0];
*guard[0] = x;
});
+ threads.push(th);
+ }
+
+ for thread in threads {
+ _ = thread.join();
}
let key = ThreadKey::get().unwrap();