Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions base/task.jl
Original file line number Diff line number Diff line change
Expand Up @@ -435,19 +435,21 @@ function _wait_multiple(waiting_tasks, throwexc=false, all=false, failfast=false
done_mask[i] = true
exception |= istaskfailed(t)
nremaining -= 1
else
done_mask[i] = false
end
end

if nremaining == 0
return tasks, Task[]
elseif any(done_mask) && (!all || (failfast && exception))
# We can return early all tasks are done, or if any is done and we only
# needed to wait for one, or if any task failed and we have failfast
if nremaining == 0 || (any(done_mask) && (!all || (failfast && exception)))
if throwexc && (!all || failfast) && exception
exceptions = [TaskFailedException(t) for t in tasks[done_mask] if istaskfailed(t)]
throw(CompositeException(exceptions))
else
return tasks[done_mask], tasks[.~done_mask]
if nremaining == 0
return tasks, Task[]
else
return tasks[done_mask], tasks[.~done_mask]
end
end
end

Expand Down Expand Up @@ -489,6 +491,10 @@ function _wait_multiple(waiting_tasks, throwexc=false, all=false, failfast=false
close(chan)

if nremaining == 0
if throwexc && exception
exceptions = [TaskFailedException(t) for t in tasks if istaskfailed(t)]
throw(CompositeException(exceptions))
end
return tasks, Task[]
else
remaining_mask = .~done_mask
Expand Down
11 changes: 11 additions & 0 deletions test/threads_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,17 @@ end
@test !istaskdone(tasks[3])

teardown(tasks, event)

@test_throws CompositeException begin
waitall(Threads.@spawn(div(1, i)) for i = 0:1)
end

tasks = [Threads.@spawn(div(1, i)) for i = 0:1]
wait(tasks[1]; throw=false)
wait(tasks[2]; throw=false)
@test_throws CompositeException begin
waitall(Threads.@spawn(div(1, i)) for i = 0:1)
end
end
end
end
Expand Down