DSP.jl
DSP.jl copied to clipboard
Latent data race in `WelchConfig`
The WelchConfig docstring has an interesting nugget:
https://github.com/JuliaDSP/DSP.jl/blob/d08699ae3cf37f973a7e77054383a8928bf5c2da/src/periodograms.jl#L545-L549
The latter part encourages re-use, but the former part hints that concurrent re-use may have a race condition. It might be useful to call this out explicitly so that a naive
config = WelchConfig(...)
psds = Vector{Periodogram}(undef, length(signals))
Threads.@threads for (idx, sig) in enumerate(signals)
psds[idx] = welch_pgram(sig, config)
end
doesn't become a user footgun
Yeah, that's true for most of the configs. Maybe a warning is warranted but OTOH it should be obvious because it is stated that buffers are pre-allocated.
Then again, that isn't really implicit in the common understanding of config. I guess this should be done...