diff options
| author | Mica White <botahamec@outlook.com> | 2024-03-10 11:08:50 -0400 |
|---|---|---|
| committer | Mica White <botahamec@outlook.com> | 2024-03-10 11:08:50 -0400 |
| commit | 61d709c211132adcc5158ded77c17d690ad5f8da (patch) | |
| tree | 181195bc8c659721dc48df83a14798f6944623ec /examples/double_mutex.rs | |
| parent | ff8c634a303d4a4133accf5fbff375046f022c7f (diff) | |
OwnedLockable
Diffstat (limited to 'examples/double_mutex.rs')
| -rw-r--r-- | examples/double_mutex.rs | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/examples/double_mutex.rs b/examples/double_mutex.rs index df11b7a..320f461 100644 --- a/examples/double_mutex.rs +++ b/examples/double_mutex.rs @@ -4,16 +4,14 @@ use happylock::{LockCollection, Mutex, ThreadKey}; const N: usize = 10; -static DATA_1: Mutex<i32> = Mutex::new(0); -static DATA_2: Mutex<String> = Mutex::new(String::new()); +static DATA: (Mutex<i32>, Mutex<String>) = (Mutex::new(0), Mutex::new(String::new())); fn main() { let mut threads = Vec::new(); for _ in 0..N { let th = thread::spawn(move || { let key = ThreadKey::lock().unwrap(); - let data = (&DATA_1, &DATA_2); - let lock = LockCollection::new(data).unwrap(); + let lock = LockCollection::new_ref(&DATA); let mut guard = lock.lock(key); *guard.1 = (100 - *guard.0).to_string(); *guard.0 += 1; @@ -26,8 +24,7 @@ fn main() { } let key = ThreadKey::lock().unwrap(); - let data = (&DATA_1, &DATA_2); - let data = LockCollection::new(data).unwrap(); + let data = LockCollection::new_ref(&DATA); let data = data.lock(key); println!("{}", *data.0); println!("{}", *data.1); |
