Skip to content

Instantly share code, notes, and snippets.

Created January 21, 2014 01:51
Show Gist options
  • Save anonymous/8533006 to your computer and use it in GitHub Desktop.
Save anonymous/8533006 to your computer and use it in GitHub Desktop.
whispers.rs
static N:int = 100000;
static StackSize:uint = 16*1024;
fn whisper(left: SharedChan<int>, right: Port<int>) {
left.send(right.recv() + 1)
}
fn main() {
let (leftmost_port, leftmost_chan) = SharedChan::new();
let mut leftc: SharedChan<int> = leftmost_chan;
let mut rightp: Port<int>;
for _ in range(0, N) {
let (right_port, right_chan) = SharedChan::new();
rightp = right_port;
let c = leftc;
let p = rightp;
do std::rt::thread::Thread::spawn_stack(StackSize) {
whisper(c, p);
}
leftc = right_chan;
}
let rightmost_chan = leftc;
do std::rt::thread::Thread::spawn_stack(StackSize) {
rightmost_chan.send(2);
}
println!("{}", leftmost_port.recv());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment