Created
January 21, 2014 01:51
-
-
Save anonymous/8533006 to your computer and use it in GitHub Desktop.
whispers.rs
This file contains hidden or 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
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