From c337fd5467f52b5f79f653b7e71f945cc8cf09d1 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 6 Sep 2011 18:16:39 -0700 Subject: [PATCH] Child tasks take a ref to their parents This is so that when a child dies after the parent, it still holds a valid pointer and can call supervisor->kill() safely. --- src/rt/rust_task.cpp | 10 ++++++++++ src/test/run-fail/spawnfail.rs | 14 ++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/test/run-fail/spawnfail.rs diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp index ab29b106783..31a3324f1d4 100644 --- a/src/rt/rust_task.cpp +++ b/src/rt/rust_task.cpp @@ -86,6 +86,9 @@ rust_task::rust_task(rust_scheduler *sched, rust_task_list *state, stk = new_stk(sched, this, 0); user.rust_sp = stk->limit; + if (supervisor) { + supervisor->ref(); + } } rust_task::~rust_task() @@ -107,6 +110,10 @@ rust_task::~rust_task() } } + if (supervisor) { + supervisor->deref(); + } + kernel->release_task_id(user.id); /* FIXME: tighten this up, there are some more @@ -294,6 +301,9 @@ rust_task::unsupervise() "task %s @0x%" PRIxPTR " disconnecting from supervisor %s @0x%" PRIxPTR, name, this, supervisor->name, supervisor); + if (supervisor) { + supervisor->deref(); + } supervisor = NULL; propagate_failure = false; } diff --git a/src/test/run-fail/spawnfail.rs b/src/test/run-fail/spawnfail.rs new file mode 100644 index 00000000000..0ff641fbe95 --- /dev/null +++ b/src/test/run-fail/spawnfail.rs @@ -0,0 +1,14 @@ +// Currently failure doesn't propagate correctly to owning tasks so xfailed +// xfail-test +// error-pattern:explicit +use std; +import std::task; + +// We don't want to see any invalid reads +fn main() { + fn f() { + fail; + } + let g = f; + task::spawn(g); +} \ No newline at end of file