mirror of
https://git.aramjonghu.dev/AramJonghu/rustlings.git
synced 2026-09-03 08:43:30 +02:00
threads2 solution
This commit is contained in:
@@ -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]]
|
||||
|
||||
Reference in New Issue
Block a user