Reference escapes thread scope
Review this Rust code that shares a slice with a scoped-looking thread.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.
0:00 of about 35 min
Mark a line and say what kind of problem it is.0 findings
1use std::thread;
2
3fn process(data: &[u8]) -> u32 {
4 data.iter().map(|&b| b as u32).sum()
5}
6
7fn run() -> u32 {
8 let buf = vec![1u8, 2, 3, 4];
9 let r = &buf;
10 let handle = thread::spawn(move || process(r));
11 let total = handle.join().unwrap();
12 drop(buf);
13 total
14}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.