From b95ddf1e7ef5520e04ab93ee7247fcf8cb800a89 Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Wed, 23 Oct 2024 12:03:09 +0200 Subject: [PATCH] Exercise 07-03 --- exercises/07_threads/03_leak/src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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)] -- 2.45.2