summary refs log tree commit diff
path: root/src/test/run-pass/many.rs
blob: 9083e1841c7a747239665f11ce7fa1a285213c2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// -*- rust -*-

use std;
import task;
import comm;

fn sub(parent: comm::chan<int>, id: int) {
    if id == 0 {
        comm::send(parent, 0);
    } else {
        let p = comm::port();
        let ch = comm::chan(p);
        let child = task::spawn(|| sub(ch, id - 1) );
        let y = comm::recv(p);
        comm::send(parent, y + 1);
    }
}

fn main() {
    let p = comm::port();
    let ch = comm::chan(p);
    let child = task::spawn(|| sub(ch, 200) );
    let y = comm::recv(p);
    #debug("transmission complete");
    log(debug, y);
    assert (y == 200);
}