From 883f31752b990304a0fa6a568ee9a6e5d97d9b36 Mon Sep 17 00:00:00 2001 From: Constantin Berhard Date: Mon, 28 Sep 2015 15:43:11 +0200 Subject: [PATCH] Arc1 code added --- standard_library_types/arc1.rs | 52 ++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 standard_library_types/arc1.rs diff --git a/standard_library_types/arc1.rs b/standard_library_types/arc1.rs new file mode 100644 index 0000000..f86f721 --- /dev/null +++ b/standard_library_types/arc1.rs @@ -0,0 +1,52 @@ +// make this code compile and don't create any copies of the "numbers" Vec. +// scroll down for hints + +use std::sync::Arc; +use std::thread; + +fn main() { + let numbers: Vec<_> = (0..100u32).collect(); + let shared_numbers = // TODO + let mut joinhandles = Vec::new(); + + for offset in 0..5 { + joinhandles.push( + thread::spawn(move || { + let mut i = offset; + let mut sum = 0; + while i