Skip to content

Commit

Permalink
track queued thread count
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Mar 27, 2022
1 parent 17bc81a commit 19f7f37
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/providers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ function set_provider!(provider; export_prefs::Bool = false)
end
end

const num_queued_threads = Threads.Atomic{Int}(0)

# If we're using fftw_jll, load it in
@static if fftw_provider == "fftw"
import FFTW_jll
Expand All @@ -55,7 +57,14 @@ end
# tasks (FFTW/fftw3#175):
function spawnloop(f::Ptr{Cvoid}, fdata::Ptr{Cvoid}, elsize::Csize_t, num::Cint, callback_data::Ptr{Cvoid})
@sync for i = 0:num-1
Threads.@spawn ccall(f, Ptr{Cvoid}, (Ptr{Cvoid},), fdata + elsize*i)
Threads.@spawn begin
Threads.atomic_add!(num_queued_threads, 1)
try
ccall(f, Ptr{Cvoid}, (Ptr{Cvoid},), fdata + elsize*i)
finally
Threads.atomic_sub!(num_queued_threads, 1)
end
end
end
end

Expand Down

0 comments on commit 19f7f37

Please # to comment.