1
1
// 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
+
2
16
// 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!
5
19
// Execute `rustlings hint arc1` for hints :)
6
20
7
21
// I AM NOT DONE
@@ -16,6 +30,7 @@ fn main() {
16
30
let mut joinhandles = Vec :: new ( ) ;
17
31
18
32
for offset in 0 ..8 {
33
+ let child_numbers = // TODO
19
34
joinhandles. push ( thread:: spawn ( move || {
20
35
let mut i = offset;
21
36
let mut sum = 0 ;
0 commit comments