Skip to content

Instantly share code, notes, and snippets.

@eddyb
Forked from anonymous/gist:bf03eca107838fbd2223
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eddyb/7ccc51d2bec250053154 to your computer and use it in GitHub Desktop.
Save eddyb/7ccc51d2bec250053154 to your computer and use it in GitHub Desktop.
static NTASKS: uint = 10;
fn main() {
let mut array = [0u, ..NTASKS];
for (x, i) in array.mut_iter().enumerate() {
let ptr = x as *mut _;
spawn(proc() {
let inner_x = unsafe {&mut *ptr};
*inner_x += i;
println!("inner_x: {}", *inner_x);
});
}
// Needs to wait on all the spawned tasks here.
println!("array: {}", array.as_slice());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment