Skip to content
This repository
Newer
Older
100644 73 lines (62 sloc) 1.505 kb
0438e6e9 »
2012-02-15 bench: Add a test for task concurrency
1 // Test for concurrent tasks
2
3 enum msg {
4 ready(comm::chan<msg>),
5 start,
6 done(int),
7 }
8
9 fn calc(children: uint, parent_ch: comm::chan<msg>) {
10 let port = comm::port();
11 let chan = comm::chan(port);
98e161f0 »
2012-06-29 Switch the compiler over to using ~[] notation instead of []/~. Closes
12 let mut child_chs = ~[];
dc07280b »
2012-03-22 make --enforce-mut-vars always on, add mut annotations to remaining f…
13 let mut sum = 0;
0438e6e9 »
2012-02-15 bench: Add a test for task concurrency
14
15 iter::repeat (children) {||
16 task::spawn {||
17 calc(0u, chan);
18 };
19 }
20
21 iter::repeat (children) {||
22 alt check comm::recv(port) {
23 ready(child_ch) {
b19c98ea »
2012-06-25 Some perf fixes, although vec::slice is still too slow (Issue #2719)
24 vec::push(child_chs, child_ch);
0438e6e9 »
2012-02-15 bench: Add a test for task concurrency
25 }
26 }
27 }
28
29 comm::send(parent_ch, ready(chan));
30
31 alt check comm::recv(port) {
32 start {
33 vec::iter (child_chs) { |child_ch|
34 comm::send(child_ch, start);
35 }
36 }
37 }
38
39 iter::repeat (children) {||
40 alt check comm::recv(port) {
41 done(child_sum) { sum += child_sum; }
42 }
43 }
44
45 comm::send(parent_ch, done(sum + 1));
46 }
47
98e161f0 »
2012-06-29 Switch the compiler over to using ~[] notation instead of []/~. Closes
48 fn main(args: ~[str]) {
4fec4cd8 »
2012-05-23 bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
49 let args = if os::getenv("RUST_BENCH").is_some() {
98e161f0 »
2012-06-29 Switch the compiler over to using ~[] notation instead of []/~. Closes
50 ~["", "100000"]
4fec4cd8 »
2012-05-23 bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
51 } else if args.len() <= 1u {
98e161f0 »
2012-06-29 Switch the compiler over to using ~[] notation instead of []/~. Closes
52 ~["", "100"]
0438e6e9 »
2012-02-15 bench: Add a test for task concurrency
53 } else {
4fec4cd8 »
2012-05-23 bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
54 args
0438e6e9 »
2012-02-15 bench: Add a test for task concurrency
55 };
4fec4cd8 »
2012-05-23 bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
56
57 let children = uint::from_str(args[1]).get();
0438e6e9 »
2012-02-15 bench: Add a test for task concurrency
58 let port = comm::port();
59 let chan = comm::chan(port);
60 task::spawn {||
61 calc(children, chan);
62 };
63 alt check comm::recv(port) {
64 ready(chan) {
65 comm::send(chan, start);
66 }
67 }
68 let sum = alt check comm::recv(port) {
69 done(sum) { sum }
70 };
71 #error("How many tasks? %d tasks.", sum);
329eca60 »
2012-06-25 Make vectors uglier ([]/~). Sorry. Should be temporary. Closes #2725.
72 }
Something went wrong with that request. Please try again.