Skip to content

Commit

Permalink
Prevent ABA problem
Browse files Browse the repository at this point in the history
  • Loading branch information
kpamnany committed Jan 6, 2025
1 parent 904e641 commit 8429be8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions base/condition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ function wait(c::GenericCondition; first::Bool=false, timeout::Real=0.0)
token = unlockall(c.lock)

timer::Union{Timer, Nothing} = nothing
waiter_left = Atomic{Bool}(false)
if timeout > 0.0
timer = Timer(timeout)
# start a task to wait on the timer
Expand All @@ -160,7 +161,7 @@ function wait(c::GenericCondition; first::Bool=false, timeout::Real=0.0)
# Confirm that the waiting task is still in the wait queue and remove it. If
# the task is not in the wait queue, it must have been notified already so we
# don't do anything here.
if ct.queue == c.waitq
if !waiter_left[] && ct.queue == c.waitq
dosched = true
Base.list_deletefirst!(c.waitq, ct)
end
Expand All @@ -174,7 +175,10 @@ function wait(c::GenericCondition; first::Bool=false, timeout::Real=0.0)

try
res = wait()
timer === nothing || close(timer)
if timer !== nothing
close(timer)
waiter_left[] = true
end
return res
catch
q = ct.queue; q === nothing || Base.list_deletefirst!(q::IntrusiveLinkedList{Task}, ct)
Expand Down

0 comments on commit 8429be8

Please sign in to comment.