Skip to content

Commit 9f997fc

Browse files
authored
tasks: Don't make parent sticky in finalizer (#48919)
1 parent 441c570 commit 9f997fc

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

base/condition.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function _wait2(c::GenericCondition, waiter::Task, first::Bool=false)
8787
push!(c.waitq, waiter)
8888
end
8989
# since _wait2 is similar to schedule, we should observe the sticky bit now
90-
if waiter.sticky && Threads.threadid(waiter) == 0
90+
if waiter.sticky && Threads.threadid(waiter) == 0 && !GC.in_finalizer()
9191
# Issue #41324
9292
# t.sticky && tid == 0 is a task that needs to be co-scheduled with
9393
# the parent task. If the parent (current_task) is not sticky we must

base/task.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ function _wait2(t::Task, waiter::Task)
323323
unlock(t.donenotify)
324324
# since _wait2 is similar to schedule, we should observe the sticky
325325
# bit, even if we aren't calling `schedule` due to this early-return
326-
if waiter.sticky && Threads.threadid(waiter) == 0
326+
if waiter.sticky && Threads.threadid(waiter) == 0 && !GC.in_finalizer()
327327
# Issue #41324
328328
# t.sticky && tid == 0 is a task that needs to be co-scheduled with
329329
# the parent task. If the parent (current_task) is not sticky we must
@@ -771,7 +771,7 @@ function enq_work(t::Task)
771771
# Sticky tasks go into their thread's work queue.
772772
if t.sticky
773773
tid = Threads.threadid(t)
774-
if tid == 0
774+
if tid == 0 && !GC.in_finalizer()
775775
# The task is not yet stuck to a thread. Stick it to the current
776776
# thread and do the same to the parent task (the current task) so
777777
# that the tasks are correctly co-scheduled (issue #41324).

0 commit comments

Comments
 (0)