2012-08-01 23:07:12 -05:00
|
|
|
// Test performance of a task "spawn ladder", in which children task have many
|
|
|
|
// many ancestor taskgroups, but with only a few such groups alive at a time.
|
|
|
|
// Each child task has to enlist as a descendant in each of its ancestor
|
|
|
|
// groups, but that shouldn't have to happen for already-dead groups.
|
|
|
|
//
|
2012-08-03 18:26:25 -05:00
|
|
|
// The filename is a song reference; google it in quotes.
|
2012-08-01 23:07:12 -05:00
|
|
|
|
2012-08-06 16:15:44 -05:00
|
|
|
fn child_generation(gens_left: uint, -c: pipes::chan<()>) {
|
2012-08-01 23:07:12 -05:00
|
|
|
// This used to be O(n^2) in the number of generations that ever existed.
|
|
|
|
// With this code, only as many generations are alive at a time as tasks
|
2012-08-03 18:26:25 -05:00
|
|
|
// alive at a time,
|
2012-08-20 14:23:37 -05:00
|
|
|
let c = ~mut Some(c);
|
2012-08-01 23:07:12 -05:00
|
|
|
do task::spawn_supervised {
|
2012-08-06 16:15:44 -05:00
|
|
|
let c = option::swap_unwrap(c);
|
2012-08-01 23:07:12 -05:00
|
|
|
if gens_left & 1 == 1 {
|
|
|
|
task::yield(); // shake things up a bit
|
|
|
|
}
|
|
|
|
if gens_left > 0 {
|
2012-08-06 16:15:44 -05:00
|
|
|
child_generation(gens_left - 1, c); // recurse
|
|
|
|
} else {
|
|
|
|
c.send(())
|
2012-08-01 23:07:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main(args: ~[~str]) {
|
|
|
|
let args = if os::getenv(~"RUST_BENCH").is_some() {
|
|
|
|
~[~"", ~"100000"]
|
|
|
|
} else if args.len() <= 1u {
|
|
|
|
~[~"", ~"100"]
|
|
|
|
} else {
|
|
|
|
copy args
|
|
|
|
};
|
|
|
|
|
2012-08-06 16:15:44 -05:00
|
|
|
let (c,p) = pipes::stream();
|
|
|
|
child_generation(uint::from_str(args[1]).get(), c);
|
|
|
|
if p.try_recv().is_none() {
|
|
|
|
fail ~"it happened when we slumbered";
|
|
|
|
}
|
2012-08-01 23:07:12 -05:00
|
|
|
}
|