Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 73 lines (62 sloc) 1.547 kB
0438e6e @brson bench: Add a test for task concurrency
brson authored
1 // Test for concurrent tasks
2
3 enum msg {
9c6890f @brson Convert more core types to camel case
brson authored
4 ready(comm::Chan<msg>),
0438e6e @brson bench: Add a test for task concurrency
brson authored
5 start,
6 done(int),
7 }
8
9c6890f @brson Convert more core types to camel case
brson authored
9 fn calc(children: uint, parent_ch: comm::Chan<msg>) {
0438e6e @brson bench: Add a test for task concurrency
brson authored
10 let port = comm::port();
11 let chan = comm::chan(port);
98e161f @msullivan Switch the compiler over to using ~[] notation instead of []/~. Close…
msullivan authored
12 let mut child_chs = ~[];
dc07280 @nikomatsakis make --enforce-mut-vars always on, add mut annotations to remaining f…
nikomatsakis authored
13 let mut sum = 0;
0438e6e @brson bench: Add a test for task concurrency
brson authored
14
f2e2a14 @bstrie Remove empty argument lists from do expressions
bstrie authored
15 for iter::repeat (children) {
16 do task::spawn {
0438e6e @brson bench: Add a test for task concurrency
brson authored
17 calc(0u, chan);
18 };
19 }
20
f2e2a14 @bstrie Remove empty argument lists from do expressions
bstrie authored
21 for iter::repeat (children) {
ecaf9e3 @brson Convert alt to match. Stop parsing alt
brson authored
22 match check comm::recv(port) {
025d866 @brson Switch alts to use arrows
brson authored
23 ready(child_ch) => {
b19c98e @eholk Some perf fixes, although vec::slice is still too slow (Issue #2719)
eholk authored
24 vec::push(child_chs, child_ch);
0438e6e @brson bench: Add a test for task concurrency
brson authored
25 }
26 }
27 }
28
29 comm::send(parent_ch, ready(chan));
30
ecaf9e3 @brson Convert alt to match. Stop parsing alt
brson authored
31 match check comm::recv(port) {
025d866 @brson Switch alts to use arrows
brson authored
32 start => {
d1fc2b5 @brson Convert to new closure syntax
brson authored
33 do vec::iter (child_chs) |child_ch| {
0438e6e @brson bench: Add a test for task concurrency
brson authored
34 comm::send(child_ch, start);
35 }
36 }
37 }
38
f2e2a14 @bstrie Remove empty argument lists from do expressions
bstrie authored
39 for iter::repeat (children) {
ecaf9e3 @brson Convert alt to match. Stop parsing alt
brson authored
40 match check comm::recv(port) {
025d866 @brson Switch alts to use arrows
brson authored
41 done(child_sum) => { sum += child_sum; }
0438e6e @brson bench: Add a test for task concurrency
brson authored
42 }
43 }
44
45 comm::send(parent_ch, done(sum + 1));
46 }
47
92743dc @msullivan Move the world over to using the new style string literals and types.…
msullivan authored
48 fn main(args: ~[~str]) {
49 let args = if os::getenv(~"RUST_BENCH").is_some() {
50 ~[~"", ~"100000"]
4fec4cd @brson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
51 } else if args.len() <= 1u {
92743dc @msullivan Move the world over to using the new style string literals and types.…
msullivan authored
52 ~[~"", ~"100"]
0438e6e @brson bench: Add a test for task concurrency
brson authored
53 } else {
4fec4cd @brson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
54 args
0438e6e @brson bench: Add a test for task concurrency
brson authored
55 };
4fec4cd @brson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
56
57 let children = uint::from_str(args[1]).get();
0438e6e @brson bench: Add a test for task concurrency
brson authored
58 let port = comm::port();
59 let chan = comm::chan(port);
f2e2a14 @bstrie Remove empty argument lists from do expressions
bstrie authored
60 do task::spawn {
0438e6e @brson bench: Add a test for task concurrency
brson authored
61 calc(children, chan);
62 };
ecaf9e3 @brson Convert alt to match. Stop parsing alt
brson authored
63 match check comm::recv(port) {
025d866 @brson Switch alts to use arrows
brson authored
64 ready(chan) => {
0438e6e @brson bench: Add a test for task concurrency
brson authored
65 comm::send(chan, start);
66 }
67 }
ecaf9e3 @brson Convert alt to match. Stop parsing alt
brson authored
68 let sum = match check comm::recv(port) {
025d866 @brson Switch alts to use arrows
brson authored
69 done(sum) => { sum }
0438e6e @brson bench: Add a test for task concurrency
brson authored
70 };
a9cc506 @paulstansifer Change syntax extension syntax: `#m[...]` -> `m!{...}`.
paulstansifer authored
71 error!{"How many tasks? %d tasks.", sum};
329eca6 @msullivan Make vectors uglier ([]/~). Sorry. Should be temporary. Closes #2725.
msullivan authored
72 }
Something went wrong with that request. Please try again.