Skip to content

Commit c337fd5

Browse files
committed
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.
1 parent 25ae3d6 commit c337fd5

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/rt/rust_task.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ rust_task::rust_task(rust_scheduler *sched, rust_task_list *state,
8686

8787
stk = new_stk(sched, this, 0);
8888
user.rust_sp = stk->limit;
89+
if (supervisor) {
90+
supervisor->ref();
91+
}
8992
}
9093

9194
rust_task::~rust_task()
@@ -107,6 +110,10 @@ rust_task::~rust_task()
107110
}
108111
}
109112

113+
if (supervisor) {
114+
supervisor->deref();
115+
}
116+
110117
kernel->release_task_id(user.id);
111118

112119
/* FIXME: tighten this up, there are some more
@@ -294,6 +301,9 @@ rust_task::unsupervise()
294301
"task %s @0x%" PRIxPTR
295302
" disconnecting from supervisor %s @0x%" PRIxPTR,
296303
name, this, supervisor->name, supervisor);
304+
if (supervisor) {
305+
supervisor->deref();
306+
}
297307
supervisor = NULL;
298308
propagate_failure = false;
299309
}

src/test/run-fail/spawnfail.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Currently failure doesn't propagate correctly to owning tasks so xfailed
2+
// xfail-test
3+
// error-pattern:explicit
4+
use std;
5+
import std::task;
6+
7+
// We don't want to see any invalid reads
8+
fn main() {
9+
fn f() {
10+
fail;
11+
}
12+
let g = f;
13+
task::spawn(g);
14+
}

0 commit comments

Comments
 (0)