Skip to content

Commit 0cfd6f2

Browse files
committed
Delay donenotify unlock in _wait2 to avoid a race
1 parent 249a5c8 commit 0cfd6f2

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

base/task.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ function _wait2(t::Task, waiter::Task)
320320
lock(t.donenotify)
321321
if !istaskdone(t)
322322
push!(t.donenotify.waitq, waiter)
323-
unlock(t.donenotify)
324323
# since _wait2 is similar to schedule, we should observe the sticky
325324
# bit, even if we aren't calling `schedule` due to this early-return
326325
if waiter.sticky && Threads.threadid(waiter) == 0 && !GC.in_finalizer()
@@ -333,6 +332,7 @@ function _wait2(t::Task, waiter::Task)
333332
tid = Threads.threadid()
334333
ccall(:jl_set_task_tid, Cint, (Any, Cint), waiter, tid-1)
335334
end
335+
unlock(t.donenotify)
336336
return nothing
337337
else
338338
unlock(t.donenotify)

0 commit comments

Comments
 (0)