Skip to content

Commit 73fd87b

Browse files
brsongraydon
authored andcommitted
Don't attempt to wake tasks that aren't blocked.
It's possible for a supervised task to kill and wake its supervising task then immediately try to wake it again if the supervising task has joined the supervised. This is the easiest way to prevent that.
1 parent 2ec4325 commit 73fd87b

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/rt/rust_task.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ rust_task::notify_tasks_waiting_to_join() {
420420
delete waiting_task;
421421
} else {
422422
rust_task *task = waiting_task->referent();
423-
if (task->dead() == false) {
423+
if (task->blocked() == true) {
424424
task->wakeup(this);
425425
}
426426
}

src/test/run-pass/task-killjoin.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Create a task that is supervised by another task,
2+
// join the supervised task from the supervising task,
3+
// then fail the supervised task. The supervised task
4+
// will kill the supervising task, waking it up. The
5+
// supervising task no longer needs to be wakened when
6+
// the supervised task exits.
7+
8+
fn supervised() {
9+
// Yield to make sure the supervisor joins before we
10+
// fail. This is currently not needed because the supervisor
11+
// runs first, but I can imagine that changing.
12+
yield;
13+
fail;
14+
}
15+
16+
fn supervisor() {
17+
let task t = spawn "supervised" supervised();
18+
join t;
19+
}
20+
21+
fn main() {
22+
// Start the test in another domain so that
23+
// the process doesn't return a failure status as a result
24+
// of the main task being killed.
25+
let task dom2 = spawn thread "supervisor" supervisor();
26+
join dom2;
27+
}
28+
29+
// Local Variables:
30+
// mode: rust;
31+
// fill-column: 78;
32+
// indent-tabs-mode: nil
33+
// c-basic-offset: 4
34+
// buffer-file-coding-system: utf-8-unix
35+
// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
36+
// End:

0 commit comments

Comments
 (0)