Is this what is expected from the vec! macro? I would expect it to have the same behavior as the loop.
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
pub fn main() {
let count = 4;
let v1 = vec![Arc::new(AtomicUsize::new(0)); count];
let mut v2 = vec![];
for _ in 0..count {
v2.push(Arc::new(AtomicUsize::new(0)));
}
v1[0].store(42, Ordering::SeqCst);
v2[0].store(42, Ordering::SeqCst);
println!("{:?}", v1);
println!("{:?}", v2);
}
Output:
[42, 42, 42, 42]
[42, 0, 0, 0]
Errors:
Compiling playground v0.0.1 (/playground)
Finished dev [unoptimized + debuginfo] target(s) in 0.81s
Running `target/debug/playground`