Skip to content

Commit a38dd01

Browse files
committed
---
yaml --- r: 14321 b: refs/heads/try c: 0438e6e h: refs/heads/master i: 14319: 9efc0d0 v: v3
1 parent 59c14e2 commit a38dd01

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 1248c250d86af96a9c4f3ee1468d9dead10ac41b
5+
refs/heads/try: 0438e6e924f09453dceff010bb4264568afa35a0
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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);
12+
let child_chs = [];
13+
let sum = 0;
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) {
24+
child_chs += [child_ch];
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+
48+
fn main(args: [str]) {
49+
let children = if vec::len(args) == 2u {
50+
uint::from_str(args[1])
51+
} else {
52+
100u
53+
};
54+
let port = comm::port();
55+
let chan = comm::chan(port);
56+
task::spawn {||
57+
calc(children, chan);
58+
};
59+
alt check comm::recv(port) {
60+
ready(chan) {
61+
comm::send(chan, start);
62+
}
63+
}
64+
let sum = alt check comm::recv(port) {
65+
done(sum) { sum }
66+
};
67+
#error("How many tasks? %d tasks.", sum);
68+
}

0 commit comments

Comments
 (0)