-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Arc example rarely executes all threads #1557
Comments
Oh, I know the reason now! The main thread ends before all threads are run. |
This way all threads are waited for: use std::sync::Arc;
use std::thread;
fn main() {
// This variable declaration is where its value is specified.
let apple = Arc::new("the same apple");
let mut threads = vec![];
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);
threads.push(thread::spawn(move || {
// As Arc was used, threads can be spawned using the value allocated
// in the Arc variable pointer's location.
println!("{:?}", apple);
}));
}
for handle in threads {
handle.join().unwrap();
}
} |
Hi c-antin, I've updated this just recently, but without using
See my PR for more: |
Should we then close this issue? |
Running the example of Arc results in a variing number of prints.
Is this a bug in rust or is

thread::spawn
not used correctly/up-to-date? Sometimes there are even incomplete prints:The text was updated successfully, but these errors were encountered: