Skip to content

Commit

Permalink
fix #13168, segfault when scheduling an already-finished task
Browse files Browse the repository at this point in the history
(cherry picked from commit 55e840b)
  • Loading branch information
JeffBezanson authored and tkelman committed Sep 17, 2015
1 parent 9e60bd8 commit 1af871b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion base/task.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ function task_done_hook(t::Task)
end
end
end
wait()
# if a finished task accidentally gets into the queue, wait()
# could return. in that case just take the next task off the queue.
while true
wait()
end
end
end

Expand Down
4 changes: 3 additions & 1 deletion src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,9 @@ JL_THREAD jl_value_t * volatile jl_task_arg_in_transit;
extern int jl_in_gc;
DLLEXPORT jl_value_t *jl_switchto(jl_task_t *t, jl_value_t *arg)
{
if (t->state == done_sym || t->state == failed_sym) {
if (t->state == done_sym || t->state == failed_sym ||
// task started but stkbuf NULL'd => finish_task ran
(t->last != NULL && t->stkbuf == NULL && t != jl_current_task)) {
if (t->exception != jl_nothing)
jl_throw(t->exception);
return t->result;
Expand Down
10 changes: 10 additions & 0 deletions test/parallel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,13 @@ let A = Any[]
end
@test length(A) == 1
end

# issue #13168
function f13168(n)
val = 0
for i=1:n val+=sum(rand(n,n)^2) end
val
end
let t = schedule(@task f13168(100))
@test schedule(t) === t
end

0 comments on commit 1af871b

Please sign in to comment.