Skip to content

Commit 40ad3aa

Browse files
committed
Fix per-thread cache+lock sizes
In Julia 1.9.0, `Threads.nthreads` returns the number of threads in the default thread pool only; previously it would return the total number of threads. We now use `Threads.maxthreadid` to determine the total number of threads.
1 parent 726541a commit 40ad3aa

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/MultiThreadedCaches.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ function init_cache!(cache::MultiThreadedCache{K,V}) where {K,V}
8282
# Statically resize the vector, but wait to lazily create the dictionaries when
8383
# requested, so that the object will be allocated on the thread that will consume it.
8484
# (This follows the guidance from Julia Base.)
85-
resize!(cache.thread_caches, Threads.nthreads())
86-
resize!(cache.thread_locks, Threads.nthreads())
85+
nt = isdefined(Base.Threads, :maxthreadid) ? Threads.maxthreadid() : Threads.nthreads()
86+
resize!(cache.thread_caches, nt)
87+
resize!(cache.thread_locks, nt)
8788
return cache
8889
end
8990

0 commit comments

Comments
 (0)