diff options
| author | Mica White <botahamec@outlook.com> | 2024-03-09 14:18:27 -0500 |
|---|---|---|
| committer | Mica White <botahamec@outlook.com> | 2024-03-09 14:18:27 -0500 |
| commit | cc96e2ce5875e8e5c28a9ede3c30b833b0bce225 (patch) | |
| tree | 7fd3d16379c75e3b155497ba1c38d8731492e16e /examples/double_mutex.rs | |
| parent | d011d5fd7f7c07f16d92106d6c92d58876fc8499 (diff) | |
Joins in example programs
Diffstat (limited to 'examples/double_mutex.rs')
| -rw-r--r-- | examples/double_mutex.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/examples/double_mutex.rs b/examples/double_mutex.rs index 1469f45..d1a939c 100644 --- a/examples/double_mutex.rs +++ b/examples/double_mutex.rs @@ -8,14 +8,20 @@ static DATA_1: Mutex<i32> = Mutex::new(0); static DATA_2: Mutex<String> = Mutex::new(String::new()); fn main() { + let mut threads = Vec::new(); for _ in 0..N { - thread::spawn(move || { + let th = thread::spawn(move || { let key = ThreadKey::lock().unwrap(); let data = (&DATA_1, &DATA_2); let mut guard = LockGuard::lock(&data, key); *guard.1 = (100 - *guard.0).to_string(); *guard.0 += 1; }); + threads.push(th); + } + + for th in threads { + _ = th.join(); } let key = ThreadKey::lock().unwrap(); |
