Code Room
Code reviewMediumcr-g584
Subject Concurrency shared mutable rustLevel Mid–Senior~28 minCommon in Concurrency interviewsIndustries Software development

Question

Review this Rust code that aggregates results across threads (assume it's been forced to compile with unsafe interior mutability).

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.

Talk through your review
Code to reviewrust
use std::sync::Arc;use std::cell::UnsafeCell;use std::thread; struct Counter { v: UnsafeCell<u64> }unsafe impl Sync for Counter {} fn main() {    let c = Arc::new(Counter { v: UnsafeCell::new(0) });    let mut hs = vec![];    for _ in 0..8 {        let c = Arc::clone(&c);        hs.push(thread::spawn(move || {            for _ in 0..100_000 {                unsafe { *c.v.get() += 1; }            }        }));    }    for h in hs { h.join().unwrap(); }    println!("{}", unsafe { *c.v.get() });}
Run or narrate your approach, then ask the coach.