Created
March 29, 2013 15:35
-
-
Save drbawb/5271578 to your computer and use it in GitHub Desktop.
rust snippet -- playing w/ MutexARC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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