From 3a1d13acfccabe357a4fb1917f53ebee2150158b Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Thu, 7 Aug 2025 18:46:13 -0400 Subject: [PATCH] Make `Base.disable_library_threading_hooks` ephemeral to the process This prevents accidentally registering hooks during the sysimage build that would persist to run-time, unlike what happens when building in a pkgimage. --- base/initdefs.jl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/base/initdefs.jl b/base/initdefs.jl index cc829f1823dd4..14b3d5d921083 100644 --- a/base/initdefs.jl +++ b/base/initdefs.jl @@ -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 @@ -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