Add task::spawn_unlinked and start migrating away from task::unsupervise
This commit is contained in:
parent
6e21b5fd22
commit
d0fb85359a
13 changed files with 39 additions and 60 deletions
|
@ -474,9 +474,7 @@ fn test_listen() {
|
|||
#[ignore(cfg(windows))]
|
||||
fn test_port_detach_fail() {
|
||||
for iter::repeat(100u) {
|
||||
let builder = task::builder();
|
||||
task::unsupervise(builder);
|
||||
do task::run(builder) {
|
||||
do task::spawn_unlinked {
|
||||
let po = port();
|
||||
let ch = po.chan();
|
||||
|
||||
|
|
|
@ -210,9 +210,7 @@ fn test_weaken_task_then_unweaken() {
|
|||
|
||||
#[test]
|
||||
fn test_weaken_task_wait() {
|
||||
let builder = task::builder();
|
||||
task::unsupervise(builder);
|
||||
do task::run(builder) {
|
||||
do task::spawn_unlinked {
|
||||
unsafe {
|
||||
do weaken_task |po| {
|
||||
comm::recv(po);
|
||||
|
@ -231,9 +229,7 @@ fn test_weaken_task_stress() {
|
|||
}
|
||||
}
|
||||
}
|
||||
let builder = task::builder();
|
||||
task::unsupervise(builder);
|
||||
do task::run(builder) {
|
||||
do task::spawn_unlinked {
|
||||
unsafe {
|
||||
do weaken_task |po| {
|
||||
// Wait for it to tell us to die
|
||||
|
|
|
@ -51,6 +51,7 @@ export run_listener;
|
|||
export run_with;
|
||||
|
||||
export spawn;
|
||||
export spawn_unlinked;
|
||||
export spawn_with;
|
||||
export spawn_listener;
|
||||
export spawn_sched;
|
||||
|
@ -430,6 +431,17 @@ fn spawn(+f: fn~()) {
|
|||
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)) {
|
||||
/*!
|
||||
* 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
|
||||
let po = comm::port();
|
||||
let ch = comm::chan(po);
|
||||
let builder = task::builder();
|
||||
task::unsupervise(builder);
|
||||
do task::run(builder) {
|
||||
let builder = task::builder();
|
||||
task::unsupervise(builder);
|
||||
do task::run(builder) {
|
||||
do task::spawn_unlinked {
|
||||
do task::spawn_unlinked {
|
||||
// Give middle task a chance to fail-but-not-kill-us.
|
||||
for iter::repeat(8192) { task::yield(); }
|
||||
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))]
|
||||
fn test_spawn_unlinked_unsup_no_fail_up() { // child unlinked fails
|
||||
let builder = task::builder();
|
||||
task::unsupervise(builder);
|
||||
do task::run(builder) { fail; }
|
||||
do task::spawn_unlinked { fail; }
|
||||
}
|
||||
#[test] #[ignore(cfg(windows))]
|
||||
fn test_spawn_unlinked_sup_no_fail_up() { // child unlinked fails
|
||||
|
|
|
@ -14,8 +14,6 @@ fn iloop() {
|
|||
|
||||
fn main() {
|
||||
for uint::range(0u, 100u) |_i| {
|
||||
let builder = task::builder();
|
||||
task::unsupervise(builder);
|
||||
task::run(builder, || iloop() );
|
||||
task::spawn_unlinked(|| iloop() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,9 +27,7 @@ fn main() {
|
|||
|
||||
sleep(iotask, 100);
|
||||
|
||||
let b = task::builder();
|
||||
task::unsupervise(b);
|
||||
task::run(b, failtest);
|
||||
task::spawn_unlinked(failtest);
|
||||
}
|
||||
|
||||
// Make sure the right thing happens during failure.
|
||||
|
|
|
@ -22,8 +22,6 @@ fn iloop() {
|
|||
|
||||
fn main() {
|
||||
for uint::range(0u, 16u) |_i| {
|
||||
let builder = task::builder();
|
||||
task::unsupervise(builder);
|
||||
task::run(builder, || iloop() );
|
||||
task::spawn_unlinked(|| iloop() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ fn joinable(f: fn~()) -> comm::port<bool> {
|
|||
}
|
||||
let p = comm::port();
|
||||
let c = comm::chan(p);
|
||||
let _ = task::spawn {|| wrapper((c, f)) };
|
||||
let _ = task::spawn_unlinked {|| wrapper((c, f)) };
|
||||
p
|
||||
}
|
||||
|
||||
|
@ -50,17 +50,14 @@ fn supervised() {
|
|||
fail;
|
||||
}
|
||||
|
||||
fn supervisor(b: task::builder) {
|
||||
// Unsupervise this task so the process doesn't return a failure status as
|
||||
// a result of the main task being killed.
|
||||
task::unsupervise(b);
|
||||
fn supervisor() {
|
||||
#error["supervisor task=%?", task::get_task()];
|
||||
let t = joinable(supervised);
|
||||
join(t);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
join(joinable({|| supervisor(task::builder())}));
|
||||
join(joinable({|| supervisor()}));
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
|
|
|
@ -20,13 +20,11 @@ fn supervisor() {
|
|||
// Unsupervise this task so the process doesn't return a failure status as
|
||||
// a result of the main task being killed.
|
||||
let f = supervised;
|
||||
task::try(|| supervised() );
|
||||
task::try(supervised);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let builder = task::builder();
|
||||
task::unsupervise(builder);
|
||||
task::run(builder, || supervisor() )
|
||||
task::spawn_unlinked(supervisor)
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
// xfail-win32
|
||||
// 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
|
||||
|
||||
fn main() {
|
||||
let builder = task::builder();
|
||||
task::unsupervise(builder);
|
||||
do task::run(builder) {
|
||||
do task::spawn_unlinked {
|
||||
fn f() { f() };
|
||||
f();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,5 @@ fn f() {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let builder = task::builder();
|
||||
task::unsupervise(builder);
|
||||
task::run(builder, || f() );
|
||||
}
|
||||
task::spawn_unlinked(f);
|
||||
}
|
||||
|
|
|
@ -21,9 +21,7 @@ fn f(c: comm::chan<bool>) {
|
|||
fn main() {
|
||||
let p = comm::port();
|
||||
let c = comm::chan(p);
|
||||
let builder = task::builder();
|
||||
task::unsupervise(builder);
|
||||
task::run(builder, || f(c) );
|
||||
task::spawn_unlinked(|| f(c) );
|
||||
#error("hiiiiiiiii");
|
||||
assert comm::recv(p);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,5 @@ fn f() {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let builder = task::builder();
|
||||
task::unsupervise(builder);
|
||||
task::run(builder, || f() );
|
||||
}
|
||||
task::spawn_unlinked(f);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,5 @@ fn f() {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let builder = task::builder();
|
||||
task::unsupervise(builder);
|
||||
task::run(builder, || f() );
|
||||
}
|
||||
task::spawn_unlinked(f);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue