Skip to content

Commit 6cd8d97

Browse files
use a Threads.Atomic counter instead
1 parent a24fb7e commit 6cd8d97

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

base/Base.jl

-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,6 @@ function __init__()
488488
if haskey(ENV, "JULIA_MAX_NUM_PRECOMPILE_FILES")
489489
MAX_NUM_PRECOMPILE_FILES[] = parse(Int, ENV["JULIA_MAX_NUM_PRECOMPILE_FILES"])
490490
end
491-
append!(empty!(TIMING_IMPORTS), zeros(Int, Threads.nthreads()))
492491
nothing
493492
end
494493

base/loading.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ function _require_from_serialized(path::String)
822822
end
823823

824824
# use an Int counter so that nested @time_imports calls all remain open
825-
const TIMING_IMPORTS = Int[] # initialized in __init__
825+
const TIMING_IMPORTS = Threads.Atomic{Int}(0)
826826

827827
# returns `true` if require found a precompile cache for this sourcepath, but couldn't load it
828828
# returns `false` if the module isn't known to be precompilable
@@ -859,7 +859,7 @@ function _require_search_from_serialized(pkg::PkgId, sourcepath::String, depth::
859859
if isa(restored, Exception)
860860
@debug "Deserialization checks failed while attempting to load cache from $path_to_try" exception=restored
861861
else
862-
if TIMING_IMPORTS[Threads.threadid()] > 0
862+
if TIMING_IMPORTS[] > 0
863863
elapsed = round((time_ns() - t_before) / 1e6, digits = 1)
864864
tree_prefix = depth == 0 ? "" : "$(" "^(depth-1))"
865865
print("$(lpad(elapsed, 9)) ms ")

stdlib/InteractiveUtils/src/macros.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ end
235235
macro time_imports(ex)
236236
quote
237237
try
238-
Base.TIMING_IMPORTS[Threads.threadid()] += 1
238+
Base.TIMING_IMPORTS[] += 1
239239
$(esc(ex))
240240
finally
241-
Base.TIMING_IMPORTS[Threads.threadid()] -= 1
241+
Base.TIMING_IMPORTS[] -= 1
242242
end
243243
end
244244
end

0 commit comments

Comments
 (0)