Skip to content

Commit f57760c

Browse files
committed
Add task-perf-linked-failure.rs
1 parent fe2f3d2 commit f57760c

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

src/test/bench/task-perf-jargon-metal-smoke.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
// Each child task has to enlist as a descendant in each of its ancestor
44
// groups, but that shouldn't have to happen for already-dead groups.
55
//
6-
// The filename is a reference; google it in quotes.
6+
// The filename is a song reference; google it in quotes.
77

88
fn child_generation(gens_left: uint) {
99
// This used to be O(n^2) in the number of generations that ever existed.
1010
// With this code, only as many generations are alive at a time as tasks
11-
// alive at a time,
11+
// alive at a time,
1212
do task::spawn_supervised {
1313
if gens_left & 1 == 1 {
1414
task::yield(); // shake things up a bit
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Test performance of killing many tasks in a taskgroup.
3+
* Along the way, tests various edge cases of ancestor group management.
4+
* In particular, this tries to get each grandchild task to hit the
5+
* "nobe_is_dead" case in each_ancestor only during task exit, but not during
6+
* task spawn. This makes sure that defunct ancestor groups are handled correctly
7+
* w.r.t. possibly leaving stale *rust_tasks lying around.
8+
*/
9+
10+
// Creates in the background 'num_tasks' tasks, all blocked forever.
11+
// Doesn't return until all such tasks are ready, but doesn't block forever itself.
12+
fn grandchild_group(num_tasks: uint) {
13+
let po = comm::port();
14+
let ch = comm::chan(po);
15+
16+
for num_tasks.times {
17+
do task::spawn { // linked
18+
comm::send(ch, ());
19+
comm::recv(comm::port::<()>()); // block forever
20+
}
21+
}
22+
#error["Grandchild group getting started"];
23+
for num_tasks.times {
24+
// Make sure all above children are fully spawned; i.e., enlisted in
25+
// their ancestor groups.
26+
comm::recv(po);
27+
}
28+
#error["Grandchild group ready to go."];
29+
// Master grandchild task exits early.
30+
}
31+
32+
fn spawn_supervised_blocking(myname: &str, +f: fn~()) {
33+
let mut res = none;
34+
task::task().future_result(|-r| res = some(r)).supervised().spawn(f);
35+
#error["%s group waiting", myname];
36+
let x = future::get(option::unwrap(res));
37+
assert x == task::success;
38+
}
39+
40+
fn main(args: ~[~str]) {
41+
let args = if os::getenv(~"RUST_BENCH").is_some() {
42+
~[~"", ~"100000"]
43+
} else if args.len() <= 1u {
44+
~[~"", ~"100"]
45+
} else {
46+
copy args
47+
};
48+
49+
let num_tasks = uint::from_str(args[1]).get();
50+
51+
// Main group #0 waits for unsupervised group #1.
52+
// Grandparent group #1 waits for middle group #2, then fails, killing #3.
53+
// Middle group #2 creates grandchild_group #3, waits for it to be ready, exits.
54+
let x: result::result<(),()> = do task::try { // unlinked
55+
do spawn_supervised_blocking("grandparent") {
56+
do spawn_supervised_blocking("middle") {
57+
grandchild_group(num_tasks);
58+
}
59+
// When grandchild group is ready to go, make the middle group exit.
60+
#error["Middle group wakes up and exits"];
61+
}
62+
// Grandparent group waits for middle group to be gone, then fails
63+
#error["Grandparent group wakes up and fails"];
64+
fail;
65+
};
66+
assert x.is_err();
67+
}

0 commit comments

Comments
 (0)