PageRenderTime 14ms CodeModel.GetById 2ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 1ms

/src/test/run-pass/basic.rs

http://github.com/jruderman/rust
Rust | 55 lines | 48 code | 6 blank | 1 comment | 2 complexity | aa88a7d0296ae8da57030a10fd6e1b09 MD5 | raw file
 1// -*- rust -*-
 2
 3use std;
 4import comm;
 5import comm::send;
 6import comm::chan;
 7import comm::recv;
 8import task;
 9
10fn a(c: chan<int>) {
11    if true {
12        debug!{"task a"};
13        debug!{"task a"};
14        debug!{"task a"};
15        debug!{"task a"};
16        debug!{"task a"};
17    }
18    send(c, 10);
19}
20
21fn k(x: int) -> int { return 15; }
22
23fn g(x: int, y: ~str) -> int {
24    log(debug, x);
25    log(debug, y);
26    let z: int = k(1);
27    return z;
28}
29
30fn main() {
31    let mut n: int = 2 + 3 * 7;
32    let s: ~str = ~"hello there";
33    let p = comm::port();
34    let ch = comm::chan(p);
35    task::spawn(|| a(ch) );
36    task::spawn(|| b(ch) );
37    let mut x: int = 10;
38    x = g(n, s);
39    log(debug, x);
40    n = recv(p);
41    n = recv(p);
42    debug!{"children finished, root finishing"};
43}
44
45fn b(c: chan<int>) {
46    if true {
47        debug!{"task b"};
48        debug!{"task b"};
49        debug!{"task b"};
50        debug!{"task b"};
51        debug!{"task b"};
52        debug!{"task b"};
53    }
54    send(c, 10);
55}