Skip to content

Commit b5ffaf6

Browse files
Merge pull request #12 from kpamnany/kp/fix-nthreads-usage
Fix per-thread cache+lock sizes
2 parents 726541a + 40ad3aa commit b5ffaf6

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)