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 ;
0 commit comments