This commit is contained in:
2025-03-26 12:41:58 -04:00
parent 637b26a0e9
commit 416dd617e6
36 changed files with 732 additions and 0 deletions

23
example_8/src/main.rs Normal file
View File

@@ -0,0 +1,23 @@
use std::rc::Rc; // reference-counted, non atomic
use std::sync::Arc; // reference-counted, atomic
fn main() {
// this will not compile:
let rc = Rc::new("not thread safe");
std::thread::spawn(move || {
println!("I have an rc with: {}", rc);
});
// this compiles fine:
let arc = Arc::new("thread safe");
std::thread::spawn(move || {
println!("I have an arc with: {}", arc);
});
// this will also not compile:
let mut v = Vec::new();
std::thread::spawn(|| {
v.push(42);
});
let _ = v.pop();
}