Arc
Arc<T>
๋ clone
๋ฉ์๋๋ฅผ ํตํด ์ฝ๊ธฐ์ ์ฉ ์ ๊ทผ์ ํ์ฉํฉ๋๋ค:
Arc<T>
allows shared read-only access via itsclone
method:
use std::thread; use std::sync::Arc; fn main() { let v = Arc::new(vec![10, 20, 30]); let mut handles = Vec::new(); for _ in 1..5 { let v = v.clone(); handles.push(thread::spawn(move || { let thread_id = thread::current().id(); println!("{thread_id:?}: {v:?}"); })); } handles.into_iter().for_each(|h| h.join().unwrap()); println!("v: {v:?}"); }