From: Greg Burri Date: Wed, 23 Oct 2024 10:03:09 +0000 (+0200) Subject: Exercise 07-03 X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=b95ddf1e7ef5520e04ab93ee7247fcf8cb800a89;p=rust_exercises.git Exercise 07-03 --- diff --git a/exercises/07_threads/03_leak/src/lib.rs b/exercises/07_threads/03_leak/src/lib.rs index b232826..18570e9 100644 --- a/exercises/07_threads/03_leak/src/lib.rs +++ b/exercises/07_threads/03_leak/src/lib.rs @@ -6,8 +6,11 @@ use std::thread; pub fn sum(v: Vec) -> i32 { - // Vec::leak(self) - todo!() + let (s1, s2) = v.leak().split_at(v.len() / 2 as usize); + let t1 = thread::spawn(|| s1.iter().sum::()); + let t2 = thread::spawn(|| s2.iter().sum::()); + + t1.join().unwrap() + t2.join().unwrap() } #[cfg(test)]