projects
/
rust_exercises.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
0522603
)
Exercise 07-03
author
Greg Burri
<greg.burri@gmail.com>
Wed, 23 Oct 2024 10:03:09 +0000
(12:03 +0200)
committer
Greg Burri
<greg.burri@gmail.com>
Wed, 23 Oct 2024 10:03:09 +0000
(12:03 +0200)
exercises/07_threads/03_leak/src/lib.rs
patch
|
blob
|
history
diff --git
a/exercises/07_threads/03_leak/src/lib.rs
b/exercises/07_threads/03_leak/src/lib.rs
index
b232826
..
18570e9
100644
(file)
--- 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>) -> i32 {
- // Vec::leak(self)
- todo!()
+ let (s1, s2) = v.leak().split_at(v.len() / 2 as usize);
+ let t1 = thread::spawn(|| s1.iter().sum::<i32>());
+ let t2 = thread::spawn(|| s2.iter().sum::<i32>());
+
+ t1.join().unwrap() + t2.join().unwrap()
}
#[cfg(test)]