Skip to content

Commit dc68ffc

Browse files
committed
Extend Threads.threadpoolsize
Allow specifying which thread pool's size to retrieve.
1 parent a70bbdf commit dc68ffc

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

base/threadingconstructs.jl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,25 @@ Returns the number of threadpools currently configured.
6666
nthreadpools() = Int(unsafe_load(cglobal(:jl_n_threadpools, Cint)))
6767

6868
"""
69-
Threads.threadpoolsize()
69+
Threads.threadpoolsize(pool::Symbol = :default) -> Int
7070
71-
Get the number of threads available to the Julia default worker-thread pool.
71+
Get the number of threads available to the default thread pool (or to the
72+
specified thread pool).
7273
7374
See also: `BLAS.get_num_threads` and `BLAS.set_num_threads` in the
7475
[`LinearAlgebra`](@ref man-linalg) standard library, and `nprocs()` in the
7576
[`Distributed`](@ref man-distributed) standard library.
7677
"""
77-
threadpoolsize() = Threads._nthreads_in_pool(Int8(0))
78+
function threadpoolsize(pool::Symbol = :default)
79+
if pool === :default
80+
tpid = Int8(0)
81+
elseif pool === :interactive
82+
tpid = Int8(1)
83+
else
84+
error("invalid threadpool specified")
85+
end
86+
return _nthreads_in_pool(tpid)
87+
end
7888

7989
function threading_run(fun, static)
8090
ccall(:jl_enter_threaded_region, Cvoid, ())

0 commit comments

Comments
 (0)