DSP.jl icon indicating copy to clipboard operation
DSP.jl copied to clipboard

Latent data race in `WelchConfig`

Open palday opened this issue 9 months ago • 2 comments

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

palday avatar Mar 10 '25 22:03 palday

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.

wheeheee avatar Mar 11 '25 04:03 wheeheee

Then again, that isn't really implicit in the common understanding of config. I guess this should be done...

wheeheee avatar Mar 11 '25 04:03 wheeheee