Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to highlight the location of slow locks #56744

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions base/lock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ end
return false
end

# Used to decide whether to warn about slow lock contention
slow_lock_warn::Int = -1 # seconds

"""
lock(lock)

Expand All @@ -175,7 +178,16 @@ Each `lock` must be matched by an [`unlock`](@ref).
# it was unlocked, so try to lock it ourself
_trylock(rl, current_task()) && break
else # it was locked, so now wait for the release to notify us
t = nothing
if slow_lock_warn >= 0
bt = backtrace()
t = Timer(slow_lock_warn) do t
@eval @warn("Taking longer than $(slow_lock_warn)s to get a lock",
exception=(ErrorException("Lock contention warning"), $bt))
end
end
wait(c)
t === nothing || close(t)
end
end
finally
Expand Down
Loading