Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 68 lines (61 sloc) 2.452 kb
f57760c Ben Blum Add task-perf-linked-failure.rs
bblum authored
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) {
161a82e Brian Anderson Camel case various core constructors
brson authored
13 let po = comm::Port();
14 let ch = comm::Chan(po);
f57760c Ben Blum Add task-perf-linked-failure.rs
bblum authored
15
16 for num_tasks.times {
17 do task::spawn { // linked
18 comm::send(ch, ());
161a82e Brian Anderson Camel case various core constructors
brson authored
19 comm::recv(comm::Port::<()>()); // block forever
f57760c Ben Blum Add task-perf-linked-failure.rs
bblum authored
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~()) {
8337fa1 Brian Anderson Camel case the option type
brson authored
33 let mut res = None;
34 task::task().future_result(|+r| res = Some(r)).supervised().spawn(f);
f57760c Ben Blum Add task-perf-linked-failure.rs
bblum authored
35 #error["%s group waiting", myname];
9600744 Graydon Hoare fix more fallout from future de-mode-ing.
graydon authored
36 let x = future::get(&option::unwrap(res));
9c6890f Brian Anderson Convert more core types to camel case
brson authored
37 assert x == task::Success;
f57760c Ben Blum Add task-perf-linked-failure.rs
bblum authored
38 }
39
267ab11 Niko Matsakis use + mode for (almost) everything when not using legacy modes
nikomatsakis authored
40 fn main(++args: ~[~str]) {
f57760c Ben Blum Add task-perf-linked-failure.rs
bblum authored
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.
0c6e470 Brian Anderson Convert core::result to camel case
brson authored
54 let x: result::Result<(),()> = do task::try { // unlinked
f57760c Ben Blum Add task-perf-linked-failure.rs
bblum authored
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 }
Something went wrong with that request. Please try again.