summary refs log tree commit diff
path: root/src/test/run-pass/unique-send-2.rs
blob: 976ca32104e95d3aa60d4233da8f3268b9bd9b91 (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
use std;
import comm;
import task;
import uint;

fn child(c: comm::chan<~uint>, i: uint) {
    comm::send(c, ~i);
}

fn main() {
    let p = comm::port();
    let ch = comm::chan(p);
    let n = 100u;
    let expected = 0u;
    uint::range(0u, n) {|i|
        task::spawn {|| child(ch, i); };
        expected += i;
    }

    let actual = 0u;
    uint::range(0u, n) {|_i|
        let j = comm::recv(p);
        actual += *j;
    }

    assert expected == actual;
}