mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-11-27 22:38:18 +02:00
Merge pull request #1929 from mo8it/threads2
threads2: simplify the exercise
This commit is contained in:
@@ -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: {}", ???);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user