summaryrefslogtreecommitdiff
path: root/exercises/20_threads/threads2.rs
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-03-27 21:24:36 +0100
committermo8it <mo8it@proton.me>2024-03-27 21:24:36 +0100
commit842e341895690aa8d59aab42d6294994ef99d10f (patch)
treec03c7c1f04c089ad3e04b44f9ac9b29ff5a5964b /exercises/20_threads/threads2.rs
parent58b03af5870ba1652f366103c241c5d11807c9bf (diff)
threads2: simplify threads2
Diffstat (limited to 'exercises/20_threads/threads2.rs')
-rw-r--r--exercises/20_threads/threads2.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/exercises/20_threads/threads2.rs b/exercises/20_threads/threads2.rs
index 62dad80..60d6824 100644
--- a/exercises/20_threads/threads2.rs
+++ b/exercises/20_threads/threads2.rs
@@ -18,7 +18,9 @@ struct JobStatus {
}
fn main() {
+ // TODO: `Arc` isn't enough if you want a **mutable** shared state
let status = Arc::new(JobStatus { jobs_completed: 0 });
+
let mut handles = vec![];
for _ in 0..10 {
let status_shared = Arc::clone(&status);
@@ -29,11 +31,12 @@ fn main() {
});
handles.push(handle);
}
+
+ // Waiting for all jobs to complete
for handle in handles {
handle.join().unwrap();
- // TODO: Print the value of the JobStatus.jobs_completed. Did you notice
- // anything interesting in the output? Do you have to 'join' on all the
- // handles?
- println!("jobs completed {}", ???);
}
+
+ // TODO: Print the value of `JobStatus.jobs_completed`
+ println!("Jobs completed: {}", ???);
}