-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Closed
Description
First, sorry if it is not a bug but the normal behavior.
I can't seem to understand why this two programs give a different answer (try):
use std::sync::Arc;
fn main() {
let numbers = vec![1i, 2i, 3i];
let numbers = Arc::new(numbers);
for num in range(0u, 3) {
let (tx, rx) = channel();
tx.send(numbers.clone());
spawn(proc() {
let numbers = rx.recv();
println!("{:d}", *numbers.get(num as uint));
})
}
}
Gives this result: 3 2 1
Changing the numbers
declaration by (try):
let numbers = Arc::new(vec![1i, 2i, 3i]);
Gives this result: 3 1 2
Also changing the order like that (try):
let numbers = Arc::new(vec![3i, 2i, 1i]);
Give this result: 1 2 3
Metadata
Metadata
Assignees
Labels
No labels