summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Macer <bobbysox322@gmail.com>2021-04-21 08:50:03 -0400
committerGitHub <noreply@github.com>2021-04-21 14:50:03 +0200
commit81be40448777fa338ebced3b0bfc1b32d6370313 (patch)
treef93c568a6ffc204e3fdaf5dfd696efcba8ffee6b
parent79cc65791715652a7f35a5b7f51309b40033cdb9 (diff)
feat(arc1): Add more details to description and hint (#710)
Co-authored-by: bmacer <bmacer@cisco.com> Co-authored-by: marisa <mokou@fastmail.com> Co-authored-by: Roberto Vidal <vidal.roberto.j@gmail.com>
-rw-r--r--exercises/standard_library_types/arc1.rs19
-rw-r--r--info.toml7
2 files changed, 23 insertions, 3 deletions
diff --git a/exercises/standard_library_types/arc1.rs b/exercises/standard_library_types/arc1.rs
index 4ad649f..d167380 100644
--- a/exercises/standard_library_types/arc1.rs
+++ b/exercises/standard_library_types/arc1.rs
@@ -1,7 +1,21 @@
// arc1.rs
+// In this exercise, we are given a Vec of u32 called "numbers" with values ranging
+// from 0 to 99 -- [ 0, 1, 2, ..., 98, 99 ]
+// We would like to use this set of numbers within 8 different threads simultaneously.
+// Each thread is going to get the sum of every eighth value, with an offset.
+// The first thread (offset 0), will sum 0, 8, 16, ...
+// The second thread (offset 1), will sum 1, 9, 17, ...
+// The third thread (offset 2), will sum 2, 10, 18, ...
+// ...
+// The eighth thread (offset 7), will sum 7, 15, 23, ...
+
+// Because we are using threads, our values need to be thread-safe. Therefore,
+// we are using Arc. We need to make a change in each of the two TODOs.
+
+
// Make this code compile by filling in a value for `shared_numbers` where the
-// TODO comment is and create an initial binding for `child_numbers`
-// somewhere. Try not to create any copies of the `numbers` Vec!
+// first TODO comment is, and create an initial binding for `child_numbers`
+// where the second TODO comment is. Try not to create any copies of the `numbers` Vec!
// Execute `rustlings hint arc1` for hints :)
// I AM NOT DONE
@@ -16,6 +30,7 @@ fn main() {
let mut joinhandles = Vec::new();
for offset in 0..8 {
+ let child_numbers = // TODO
joinhandles.push(thread::spawn(move || {
let mut i = offset;
let mut sum = 0;
diff --git a/info.toml b/info.toml
index 36dcbe9..82e1195 100644
--- a/info.toml
+++ b/info.toml
@@ -679,7 +679,12 @@ to avoid creating a copy of `numbers`, you'll need to create `child_numbers`
inside the loop but still in the main thread.
`child_numbers` should be a clone of the Arc of the numbers instead of a
-thread-local copy of the numbers."""
+thread-local copy of the numbers.
+
+This is a simple exercise if you understand the underlying concepts, but if this
+is too much of a struggle, consider reading through all of Chapter 16 in the book:
+https://doc.rust-lang.org/stable/book/ch16-00-concurrency.html
+"""
[[exercises]]
name = "iterators1"