Skip to content

Instantly share code, notes, and snippets.

@drbawb
Created March 29, 2013 15:35
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 drbawb/5271578 to your computer and use it in GitHub Desktop.
Save drbawb/5271578 to your computer and use it in GitHub Desktop.
rust snippet -- playing w/ MutexARC
extern mod std;
use core::io::*;
use std::timer::*;
struct Dog {
mut name : ~str
}
fn lol() -> int {
let snoopy = ~Dog{name: ~"snoopy"};
let mxSnoopy1 = std::arc::MutexARC(snoopy);
let mxSnoopy2 = mxSnoopy1.clone();
do task::spawn {
sleep(std::uv::global_loop::get(), 1000);
do mxSnoopy2.access |innerDog| { //moves bub2 to anonymous task
println(fmt!("%s !!!", innerDog.name)); //safe access to innerDog
}
}
do mxSnoopy1.access |innerDog| {
innerDog.name = ~"bubzie";
}
return 3;
}
fn main() {
let x = lol();
println(fmt!("%d", x));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment