2012-04-03 16:03:27 -05:00
|
|
|
// Jump back and forth between the OS main thread and a new scheduler.
|
|
|
|
// The OS main scheduler should continue to be available and not terminate
|
|
|
|
// while it is not in use.
|
|
|
|
|
|
|
|
fn main() {
|
2012-04-03 19:39:35 -05:00
|
|
|
run(100);
|
2012-04-03 16:03:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn run(i: int) {
|
|
|
|
|
|
|
|
log(debug, i);
|
|
|
|
|
|
|
|
if i == 0 {
|
|
|
|
ret;
|
|
|
|
}
|
|
|
|
|
2012-04-05 16:09:32 -05:00
|
|
|
let builder = task::builder();
|
2012-04-03 16:03:27 -05:00
|
|
|
let opts = {
|
|
|
|
sched: some({
|
|
|
|
mode: task::osmain,
|
|
|
|
native_stack_size: none
|
|
|
|
})
|
|
|
|
with task::get_opts(builder)
|
|
|
|
};
|
|
|
|
task::set_opts(builder, opts);
|
|
|
|
task::unsupervise(builder);
|
|
|
|
task::run(builder) {||
|
|
|
|
task::yield();
|
2012-04-05 16:09:32 -05:00
|
|
|
let builder = task::builder();
|
2012-04-03 16:03:27 -05:00
|
|
|
let opts = {
|
|
|
|
sched: some({
|
|
|
|
mode: task::single_threaded,
|
|
|
|
native_stack_size: none
|
|
|
|
})
|
|
|
|
with task::get_opts(builder)
|
|
|
|
};
|
|
|
|
task::set_opts(builder, opts);
|
|
|
|
task::unsupervise(builder);
|
|
|
|
task::run(builder) {||
|
|
|
|
task::yield();
|
|
|
|
run(i - 1);
|
|
|
|
task::yield();
|
|
|
|
}
|
|
|
|
task::yield();
|
|
|
|
}
|
|
|
|
}
|