complete threads till 06

This commit is contained in:
2025-04-15 16:25:01 +05:30
parent 9bc063a05b
commit 4fbee2d894
9 changed files with 67 additions and 19 deletions

View File

@@ -3,7 +3,13 @@
// Don't perform any heap allocation. Don't leak any memory.
pub fn sum(v: Vec<i32>) -> i32 {
todo!()
let mid = v.len() / 2;
let (s1, s2) = v.split_at(mid);
std::thread::scope(|scope| {
let t1 = scope.spawn(|| s1.iter().sum::<i32>());
let t2 = scope.spawn(|| s2.iter().sum::<i32>());
t1.join().unwrap() + t2.join().unwrap()
})
}
#[cfg(test)]