PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/run-pass/task-comm-6.rs

http://github.com/jruderman/rust
Rust | 42 lines | 37 code | 3 blank | 2 comment | 3 complexity | 3b15f676738e07ec51c2759142044f5b MD5 | raw file
 1use std;
 2import pipes;
 3import pipes::send;
 4import pipes::chan;
 5import pipes::recv;
 6
 7fn main() { test00(); }
 8
 9fn test00() {
10    let mut r: int = 0;
11    let mut sum: int = 0;
12    let p = pipes::port_set();
13    let c0 = p.chan();
14    let c1 = p.chan();
15    let c2 = p.chan();
16    let c3 = p.chan();
17    let number_of_messages: int = 1000;
18    let mut i: int = 0;
19    while i < number_of_messages {
20        c0.send(i + 0);
21        c1.send(i + 0);
22        c2.send(i + 0);
23        c3.send(i + 0);
24        i += 1;
25    }
26    i = 0;
27    while i < number_of_messages {
28        r = p.recv();
29        sum += r;
30        r = p.recv();
31        sum += r;
32        r = p.recv();
33        sum += r;
34        r = p.recv();
35        sum += r;
36        i += 1;
37    }
38    assert (sum == 1998000);
39    // assert (sum == 4 * ((number_of_messages *
40    //                   (number_of_messages - 1)) / 2));
41
42}