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

Conversation

IanButterworth
Copy link
Member

Replaces #55120

Without something like this, it can be quite tricky to figure out where slow locks are happening.

julia> Base.slow_lock_warn = 1
1

julia> @sync begin
       l = ReentrantLock()
       @async begin
           lock(l) do
               sleep(2)
           end
       end
       @async begin
           lock(l) do
               sleep(2)
           end
       end
       end
┌ Warning: Taking longer than 1s to get a lock
│   exception =
│    Lock contention warning
│    Stacktrace:
│     [1] (::Base.var"#slowlock#lock##14")(rl::ReentrantLock)
│       @ Base ./REPL[8]:14
│     [2] lock
│       @ ./REPL[8]:2 [inlined]
│     [3] lock(f::var"#47#48", l::ReentrantLock)
│       @ Base ./lock.jl:262
│     [4] (::var"#45#46"{ReentrantLock})()
│       @ Main ./REPL[9]:9
└ @ Base REPL[8]:16

@Seelengrab
Copy link
Contributor

If julia had a debug vs. release mode, this would be a very good candidate for only enabling in the former :/ Taking a backtrace and spawning a Timer are quite heavy..

@IanButterworth
Copy link
Member Author

It's disabled by default. Note the -1

@Seelengrab
Copy link
Contributor

Yes, but the code for the Timer still has to be there & visible for effects & inference, since the global is not a constant. I'd also be very anxious around some other piece of code enabling that out of perceived convenience for their code, not realizing that this could introduce unwanted prints/logs in some other library. That's not something that can happen with a true debug vs. release distinction on the compiler level :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants