Add task::spawn_unlinked and start migrating away from task::unsupervise

This commit is contained in:
Ben Blum 2012-07-23 15:53:18 -04:00
parent 6e21b5fd22
commit d0fb85359a
13 changed files with 39 additions and 60 deletions

View file

@ -474,9 +474,7 @@ fn test_listen() {
#[ignore(cfg(windows))] #[ignore(cfg(windows))]
fn test_port_detach_fail() { fn test_port_detach_fail() {
for iter::repeat(100u) { for iter::repeat(100u) {
let builder = task::builder(); do task::spawn_unlinked {
task::unsupervise(builder);
do task::run(builder) {
let po = port(); let po = port();
let ch = po.chan(); let ch = po.chan();

View file

@ -210,9 +210,7 @@ fn test_weaken_task_then_unweaken() {
#[test] #[test]
fn test_weaken_task_wait() { fn test_weaken_task_wait() {
let builder = task::builder(); do task::spawn_unlinked {
task::unsupervise(builder);
do task::run(builder) {
unsafe { unsafe {
do weaken_task |po| { do weaken_task |po| {
comm::recv(po); comm::recv(po);
@ -231,9 +229,7 @@ fn test_weaken_task_stress() {
} }
} }
} }
let builder = task::builder(); do task::spawn_unlinked {
task::unsupervise(builder);
do task::run(builder) {
unsafe { unsafe {
do weaken_task |po| { do weaken_task |po| {
// Wait for it to tell us to die // Wait for it to tell us to die

View file

@ -51,6 +51,7 @@ export run_listener;
export run_with; export run_with;
export spawn; export spawn;
export spawn_unlinked;
export spawn_with; export spawn_with;
export spawn_listener; export spawn_listener;
export spawn_sched; export spawn_sched;
@ -430,6 +431,17 @@ fn spawn(+f: fn~()) {
run(builder(), f); run(builder(), f);
} }
fn spawn_unlinked(+f: fn~()) {
/*!
* Creates a child task unlinked from the current one. If either this
* task or the child task fails, the other will not be killed.
*/
let b = builder();
unsupervise(b);
run(b, f);
}
fn spawn_with<A:send>(+arg: A, +f: fn~(+A)) { fn spawn_with<A:send>(+arg: A, +f: fn~(+A)) {
/*! /*!
* Runs a task, while transfering ownership of one argument to the * Runs a task, while transfering ownership of one argument to the
@ -1159,12 +1171,8 @@ fn test_spawn_raw_unsupervise() {
fn test_spawn_unlinked_unsup_no_fail_down() { // grandchild sends on a port fn test_spawn_unlinked_unsup_no_fail_down() { // grandchild sends on a port
let po = comm::port(); let po = comm::port();
let ch = comm::chan(po); let ch = comm::chan(po);
let builder = task::builder(); do task::spawn_unlinked {
task::unsupervise(builder); do task::spawn_unlinked {
do task::run(builder) {
let builder = task::builder();
task::unsupervise(builder);
do task::run(builder) {
// Give middle task a chance to fail-but-not-kill-us. // Give middle task a chance to fail-but-not-kill-us.
for iter::repeat(8192) { task::yield(); } for iter::repeat(8192) { task::yield(); }
comm::send(ch, ()); // If killed first, grandparent hangs. comm::send(ch, ()); // If killed first, grandparent hangs.
@ -1175,9 +1183,7 @@ fn test_spawn_unlinked_unsup_no_fail_down() { // grandchild sends on a port
} }
#[test] #[ignore(cfg(windows))] #[test] #[ignore(cfg(windows))]
fn test_spawn_unlinked_unsup_no_fail_up() { // child unlinked fails fn test_spawn_unlinked_unsup_no_fail_up() { // child unlinked fails
let builder = task::builder(); do task::spawn_unlinked { fail; }
task::unsupervise(builder);
do task::run(builder) { fail; }
} }
#[test] #[ignore(cfg(windows))] #[test] #[ignore(cfg(windows))]
fn test_spawn_unlinked_sup_no_fail_up() { // child unlinked fails fn test_spawn_unlinked_sup_no_fail_up() { // child unlinked fails

View file

@ -14,8 +14,6 @@ fn iloop() {
fn main() { fn main() {
for uint::range(0u, 100u) |_i| { for uint::range(0u, 100u) |_i| {
let builder = task::builder(); task::spawn_unlinked(|| iloop() );
task::unsupervise(builder);
task::run(builder, || iloop() );
} }
} }

View file

@ -27,9 +27,7 @@ fn main() {
sleep(iotask, 100); sleep(iotask, 100);
let b = task::builder(); task::spawn_unlinked(failtest);
task::unsupervise(b);
task::run(b, failtest);
} }
// Make sure the right thing happens during failure. // Make sure the right thing happens during failure.

View file

@ -22,8 +22,6 @@ fn iloop() {
fn main() { fn main() {
for uint::range(0u, 16u) |_i| { for uint::range(0u, 16u) |_i| {
let builder = task::builder(); task::spawn_unlinked(|| iloop() );
task::unsupervise(builder);
task::run(builder, || iloop() );
} }
} }

View file

@ -33,7 +33,7 @@ fn joinable(f: fn~()) -> comm::port<bool> {
} }
let p = comm::port(); let p = comm::port();
let c = comm::chan(p); let c = comm::chan(p);
let _ = task::spawn {|| wrapper((c, f)) }; let _ = task::spawn_unlinked {|| wrapper((c, f)) };
p p
} }
@ -50,17 +50,14 @@ fn supervised() {
fail; fail;
} }
fn supervisor(b: task::builder) { fn supervisor() {
// Unsupervise this task so the process doesn't return a failure status as
// a result of the main task being killed.
task::unsupervise(b);
#error["supervisor task=%?", task::get_task()]; #error["supervisor task=%?", task::get_task()];
let t = joinable(supervised); let t = joinable(supervised);
join(t); join(t);
} }
fn main() { fn main() {
join(joinable({|| supervisor(task::builder())})); join(joinable({|| supervisor()}));
} }
// Local Variables: // Local Variables:

View file

@ -20,13 +20,11 @@ fn supervisor() {
// Unsupervise this task so the process doesn't return a failure status as // Unsupervise this task so the process doesn't return a failure status as
// a result of the main task being killed. // a result of the main task being killed.
let f = supervised; let f = supervised;
task::try(|| supervised() ); task::try(supervised);
} }
fn main() { fn main() {
let builder = task::builder(); task::spawn_unlinked(supervisor)
task::unsupervise(builder);
task::run(builder, || supervisor() )
} }
// Local Variables: // Local Variables:

View file

@ -1,14 +1,12 @@
// xfail-win32 // xfail-win32
// error-pattern:ran out of stack // error-pattern:ran out of stack
// Test that the task fails after hiting the recursion limit, but // Test that the task fails after hitting the recursion limit, but
// that it doesn't bring down the whole proc // that it doesn't bring down the whole proc
fn main() { fn main() {
let builder = task::builder(); do task::spawn_unlinked {
task::unsupervise(builder);
do task::run(builder) {
fn f() { f() }; fn f() { f() };
f(); f();
}; };
} }

View file

@ -8,7 +8,5 @@ fn f() {
} }
fn main() { fn main() {
let builder = task::builder(); task::spawn_unlinked(f);
task::unsupervise(builder); }
task::run(builder, || f() );
}

View file

@ -21,9 +21,7 @@ fn f(c: comm::chan<bool>) {
fn main() { fn main() {
let p = comm::port(); let p = comm::port();
let c = comm::chan(p); let c = comm::chan(p);
let builder = task::builder(); task::spawn_unlinked(|| f(c) );
task::unsupervise(builder);
task::run(builder, || f(c) );
#error("hiiiiiiiii"); #error("hiiiiiiiii");
assert comm::recv(p); assert comm::recv(p);
} }

View file

@ -15,7 +15,5 @@ fn f() {
} }
fn main() { fn main() {
let builder = task::builder(); task::spawn_unlinked(f);
task::unsupervise(builder); }
task::run(builder, || f() );
}

View file

@ -8,7 +8,5 @@ fn f() {
} }
fn main() { fn main() {
let builder = task::builder(); task::spawn_unlinked(f);
task::unsupervise(builder); }
task::run(builder, || f() );
}