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.

Revisions

  1. @invalid-email-address Anonymous created this gist Jan 21, 2014.
    28 changes: 28 additions & 0 deletions whispers.rs.rs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    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());
    }