mirror of
https://github.com/ahgamut/rust-ape-example.git
synced 2024-05-15 10:02:42 +00:00
4b8d56098f
they don't run yet because of some stack size thing
31 lines
751 B
Rust
31 lines
751 B
Rust
// ./src/std/arc.md
|
|
|
|
use std::time::Duration;
|
|
use std::sync::Arc;
|
|
use std::thread;
|
|
|
|
fn part0() {
|
|
// This variable declaration is where its value is specified.
|
|
let apple = Arc::new("the same apple");
|
|
|
|
for _ in 0..10 {
|
|
// Here there is no value specification as it is a pointer to a
|
|
// reference in the memory heap.
|
|
let apple = Arc::clone(&apple);
|
|
|
|
thread::spawn(move || {
|
|
// As Arc was used, threads can be spawned using the value allocated
|
|
// in the Arc variable pointer's location.
|
|
println!("{:?}", apple);
|
|
});
|
|
}
|
|
|
|
// Make sure all Arc instances are printed from spawned threads.
|
|
thread::sleep(Duration::from_secs(1));
|
|
}
|
|
|
|
pub fn main() {
|
|
part0();
|
|
}
|
|
|