A static mut is a Rust static value that can be changed directly throughout a program. Because unsynchronized access can cause aliasing violations or data races, reading or modifying one requires an unsafe block. section 16.4 section 16.4.2
A counter shared by threads
static mut NUMBER: u32 = 0;\n\nfn main() {\n let mut handles = vec![];\n for _ in 0..10 {\n handles.push(std::thread::spawn(|| {\n for _ in 0..10 {\n unsafe { NUMBER += 1; }\n }\n }));\n }\n for handle in handles { handle.join().unwrap(); }\n unsafe { println!("{NUMBER}"); }\n}\n\nTen threads may produce 100, but increasing the test to 1,000 threads with 1,000 increments can produce inconsistent totals such as 959,696. Threads can read the same value, increment separately, and overwrite one another’s updates. section 16.4.2
The compiler diagnostic identifies mutable-static access as unsafe and names aliasing violations and data races as the reason. section 16.4.2

