threads2 solution

This commit is contained in:
mo8it
2024-07-01 11:11:11 +02:00
parent b000164eed
commit dfa2b44f71
3 changed files with 59 additions and 20 deletions
+5 -5
View File
@@ -1051,19 +1051,19 @@ dir = "20_threads"
test = false
hint = """
`Arc` is an Atomic Reference Counted pointer that allows safe, shared access
to **immutable** data. But we want to *change* the number of `jobs_completed`
so we'll need to also use another type that will only allow one thread to
mutate the data at a time. Take a look at this section of the book:
to **immutable** data. But we want to *change* the number of `jobs_done` so
we'll need to also use another type that will only allow one thread to mutate
the data at a time. Take a look at this section of the book:
https://doc.rust-lang.org/book/ch16-03-shared-state.html#atomic-reference-counting-with-arct
Keep reading if you'd like more hints :)
Do you now have an `Arc<Mutex<JobStatus>>` at the beginning of `main`? Like:
```
let status = Arc::new(Mutex::new(JobStatus { jobs_completed: 0 }));
let status = Arc::new(Mutex::new(JobStatus { jobs_done: 0 }));
```
Similar to the code in the following example in the book:
Similar to the code in the following example in The Book:
https://doc.rust-lang.org/book/ch16-03-shared-state.html#sharing-a-mutext-between-multiple-threads"""
[[exercises]]