use std::sync::Arc;
let foo = Arc::new(vec![1.0, 2.0, 3.0]);
cat src/main.rs
use std::thread;
use std::sync::Arc;
fn main() {
let data =Arc::new(vec![1,2,3,4,5]);
let cp = Arc::clone(&data);
//let cp = data.clone();
let handle =thread::spawn( move || {
println!("threadid {:?} and data.len {}", thread::current().id(), cp.len());
}
);
println!("threadid {:?} and data.len {}", thread::current().id(), data.len());
handle.join();
}
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running `target/debug/own`
threadid ThreadId(1) and data.len 5
threadid ThreadId(2) and data.len 5