summaryrefslogtreecommitdiff
path: root/examples/list.rs
diff options
context:
space:
mode:
authorMica White <botahamec@outlook.com>2024-03-09 14:18:27 -0500
committerMica White <botahamec@outlook.com>2024-03-09 14:18:27 -0500
commitcc96e2ce5875e8e5c28a9ede3c30b833b0bce225 (patch)
tree7fd3d16379c75e3b155497ba1c38d8731492e16e /examples/list.rs
parentd011d5fd7f7c07f16d92106d6c92d58876fc8499 (diff)
Joins in example programs
Diffstat (limited to 'examples/list.rs')
-rw-r--r--examples/list.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/examples/list.rs b/examples/list.rs
index 1f811db..3903260 100644
--- a/examples/list.rs
+++ b/examples/list.rs
@@ -26,8 +26,9 @@ fn random(key: &mut ThreadKey) -> usize {
}
fn main() {
+ let mut threads = Vec::new();
for _ in 0..N {
- thread::spawn(move || {
+ let th = thread::spawn(move || {
let mut key = ThreadKey::lock().unwrap();
let mut data = Vec::new();
for _ in 0..3 {
@@ -40,6 +41,11 @@ fn main() {
*guard[1] += *guard[2];
*guard[2] += *guard[0];
});
+ threads.push(th);
+ }
+
+ for th in threads {
+ _ = th.join();
}
let mut key = ThreadKey::lock().unwrap();