Skip to content
Newer
Older
100644 79 lines (68 sloc) 1.83 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>) {
161a82e @brson Camel case various core constructors
brson authored
10 let port = comm::Port();
fe12da0 @catamorphism De-mode comm::Chan
catamorphism authored
11 let chan = comm::Chan(&port);
98e161f @msullivan Switch the compiler over to using ~[] notation instead of []/~. Closes
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) {
e9622f0 @catamorphism Remove match check from test cases
catamorphism authored
22 match comm::recv(port) {
025d866 @brson Switch alts to use arrows
brson authored
23 ready(child_ch) => {
67a8e71 @nikomatsakis Demode vec::push (and convert to method)
nikomatsakis authored
24 child_chs.push(child_ch);
0438e6e @brson bench: Add a test for task concurrency
brson authored
25 }
e9622f0 @catamorphism Remove match check from test cases
catamorphism authored
26 _ => fail ~"task-perf-one-million failed (port not ready)"
0438e6e @brson bench: Add a test for task concurrency
brson authored
27 }
28 }
29
30 comm::send(parent_ch, ready(chan));
31
e9622f0 @catamorphism Remove match check from test cases
catamorphism authored
32 match comm::recv(port) {
025d866 @brson Switch alts to use arrows
brson authored
33 start => {
9cf271f @nikomatsakis De-mode vec::each() and many of the str iteration routines
nikomatsakis authored
34 for vec::each(child_chs) |child_ch| {
35 comm::send(*child_ch, start);
36 }
0438e6e @brson bench: Add a test for task concurrency
brson authored
37 }
e9622f0 @catamorphism Remove match check from test cases
catamorphism authored
38 _ => fail ~"task-perf-one-million failed (port not in start state)"
0438e6e @brson bench: Add a test for task concurrency
brson authored
39 }
40
f2e2a14 @bstrie Remove empty argument lists from do expressions
bstrie authored
41 for iter::repeat (children) {
e9622f0 @catamorphism Remove match check from test cases
catamorphism authored
42 match comm::recv(port) {
025d866 @brson Switch alts to use arrows
brson authored
43 done(child_sum) => { sum += child_sum; }
e9622f0 @catamorphism Remove match check from test cases
catamorphism authored
44 _ => fail ~"task-perf-one-million failed (port not done)"
0438e6e @brson bench: Add a test for task concurrency
brson authored
45 }
46 }
47
48 comm::send(parent_ch, done(sum + 1));
49 }
50
edc317b @brson Remove arg vectors from main functions. Stop supporting them.
brson authored
51 fn main() {
52 let args = os::args();
92743dc @msullivan Move the world over to using the new style string literals and types.…
msullivan authored
53 let args = if os::getenv(~"RUST_BENCH").is_some() {
54 ~[~"", ~"100000"]
4fec4cd @brson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
55 } else if args.len() <= 1u {
92743dc @msullivan Move the world over to using the new style string literals and types.…
msullivan authored
56 ~[~"", ~"100"]
0438e6e @brson bench: Add a test for task concurrency
brson authored
57 } else {
4fec4cd @brson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
58 args
0438e6e @brson bench: Add a test for task concurrency
brson authored
59 };
4fec4cd @brson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
60
61 let children = uint::from_str(args[1]).get();
161a82e @brson Camel case various core constructors
brson authored
62 let port = comm::Port();
fe12da0 @catamorphism De-mode comm::Chan
catamorphism authored
63 let chan = comm::Chan(&port);
f2e2a14 @bstrie Remove empty argument lists from do expressions
bstrie authored
64 do task::spawn {
0438e6e @brson bench: Add a test for task concurrency
brson authored
65 calc(children, chan);
66 };
e9622f0 @catamorphism Remove match check from test cases
catamorphism authored
67 match comm::recv(port) {
025d866 @brson Switch alts to use arrows
brson authored
68 ready(chan) => {
0438e6e @brson bench: Add a test for task concurrency
brson authored
69 comm::send(chan, start);
70 }
e9622f0 @catamorphism Remove match check from test cases
catamorphism authored
71 _ => fail ~"task-perf-one-million failed (port not ready)"
0438e6e @brson bench: Add a test for task concurrency
brson authored
72 }
e9622f0 @catamorphism Remove match check from test cases
catamorphism authored
73 let sum = match comm::recv(port) {
025d866 @brson Switch alts to use arrows
brson authored
74 done(sum) => { sum }
e9622f0 @catamorphism Remove match check from test cases
catamorphism authored
75 _ => fail ~"task-perf-one-million failed (port not done)"
0438e6e @brson bench: Add a test for task concurrency
brson authored
76 };
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
77 error!("How many tasks? %d tasks.", sum);
329eca6 @msullivan Make vectors uglier ([]/~). Sorry. Should be temporary. Closes #2725.
msullivan authored
78 }
Something went wrong with that request. Please try again.