Skip to content

Commit

Permalink
Extend Threads.threadpoolsize
Browse files Browse the repository at this point in the history
Allow specifying which thread pool's size to retrieve.
  • Loading branch information
kpamnany committed Mar 6, 2023
1 parent a70bbdf commit dc68ffc
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions base/threadingconstructs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,25 @@ Returns the number of threadpools currently configured.
nthreadpools() = Int(unsafe_load(cglobal(:jl_n_threadpools, Cint)))

"""
Threads.threadpoolsize()
Threads.threadpoolsize(pool::Symbol = :default) -> Int
Get the number of threads available to the Julia default worker-thread pool.
Get the number of threads available to the default thread pool (or to the
specified thread pool).
See also: `BLAS.get_num_threads` and `BLAS.set_num_threads` in the
[`LinearAlgebra`](@ref man-linalg) standard library, and `nprocs()` in the
[`Distributed`](@ref man-distributed) standard library.
"""
threadpoolsize() = Threads._nthreads_in_pool(Int8(0))
function threadpoolsize(pool::Symbol = :default)
if pool === :default
tpid = Int8(0)
elseif pool === :interactive
tpid = Int8(1)
else
error("invalid threadpool specified")
end
return _nthreads_in_pool(tpid)
end

function threading_run(fun, static)
ccall(:jl_enter_threaded_region, Cvoid, ())
Expand Down

0 comments on commit dc68ffc

Please sign in to comment.