Skip to content

Commit 81be404

Browse files
bmacershadows-withaljrvidal
authored
feat(arc1): Add more details to description and hint (#710)
Co-authored-by: bmacer <[email protected]> Co-authored-by: marisa <[email protected]> Co-authored-by: Roberto Vidal <[email protected]>
1 parent 79cc657 commit 81be404

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

exercises/standard_library_types/arc1.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
// arc1.rs
2+
// In this exercise, we are given a Vec of u32 called "numbers" with values ranging
3+
// from 0 to 99 -- [ 0, 1, 2, ..., 98, 99 ]
4+
// We would like to use this set of numbers within 8 different threads simultaneously.
5+
// Each thread is going to get the sum of every eighth value, with an offset.
6+
// The first thread (offset 0), will sum 0, 8, 16, ...
7+
// The second thread (offset 1), will sum 1, 9, 17, ...
8+
// The third thread (offset 2), will sum 2, 10, 18, ...
9+
// ...
10+
// The eighth thread (offset 7), will sum 7, 15, 23, ...
11+
12+
// Because we are using threads, our values need to be thread-safe. Therefore,
13+
// we are using Arc. We need to make a change in each of the two TODOs.
14+
15+
216
// Make this code compile by filling in a value for `shared_numbers` where the
3-
// TODO comment is and create an initial binding for `child_numbers`
4-
// somewhere. Try not to create any copies of the `numbers` Vec!
17+
// first TODO comment is, and create an initial binding for `child_numbers`
18+
// where the second TODO comment is. Try not to create any copies of the `numbers` Vec!
519
// Execute `rustlings hint arc1` for hints :)
620

721
// I AM NOT DONE
@@ -16,6 +30,7 @@ fn main() {
1630
let mut joinhandles = Vec::new();
1731

1832
for offset in 0..8 {
33+
let child_numbers = // TODO
1934
joinhandles.push(thread::spawn(move || {
2035
let mut i = offset;
2136
let mut sum = 0;

info.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,12 @@ to avoid creating a copy of `numbers`, you'll need to create `child_numbers`
679679
inside the loop but still in the main thread.
680680
681681
`child_numbers` should be a clone of the Arc of the numbers instead of a
682-
thread-local copy of the numbers."""
682+
thread-local copy of the numbers.
683+
684+
This is a simple exercise if you understand the underlying concepts, but if this
685+
is too much of a struggle, consider reading through all of Chapter 16 in the book:
686+
https://doc.rust-lang.org/stable/book/ch16-00-concurrency.html
687+
"""
683688

684689
[[exercises]]
685690
name = "iterators1"

0 commit comments

Comments
 (0)