Skip to content

Make Base.disable_library_threading_hooks ephemeral to the process #59232

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

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
11 changes: 7 additions & 4 deletions base/initdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,13 @@ end
## hook for disabling threaded libraries ##

library_threading_enabled::Bool = true
const disable_library_threading_hooks = []

# Base.OncePerProcess ensures that any registered hooks do not outlive the session.
# (even if they are registered during the sysimage build process by top-level code)
const disable_library_threading_hooks = Base.OncePerProcess(Vector{Any})

function at_disable_library_threading(f)
push!(disable_library_threading_hooks, f)
push!(disable_library_threading_hooks(), f)
if !library_threading_enabled
disable_library_threading()
end
Expand All @@ -506,8 +509,8 @@ end

function disable_library_threading()
global library_threading_enabled = false
while !isempty(disable_library_threading_hooks)
f = pop!(disable_library_threading_hooks)
while !isempty(disable_library_threading_hooks())
f = pop!(disable_library_threading_hooks())
try
f()
catch err
Expand Down