diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2016-06-09 09:06:19 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2016-06-09 09:06:19 -0600 |
commit | d4a39b0f0e7d5b999b834b86f4beababe23e77f1 (patch) | |
tree | aceded64acc079e83bb8036c163bd054db006a9d /numpy/fft/fftpack.py | |
parent | d69c1470ed09f18293b9a9dec1809e14b5b9b779 (diff) | |
parent | 820d527fe0bc6414ad19b10eea941a7fc0749757 (diff) | |
download | numpy-d4a39b0f0e7d5b999b834b86f4beababe23e77f1.tar.gz |
Merge pull request #7712 from krischer/fft-cache-race-condition
BUG: Fix race condition with new FFT cache
Diffstat (limited to 'numpy/fft/fftpack.py')
-rw-r--r-- | numpy/fft/fftpack.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/numpy/fft/fftpack.py b/numpy/fft/fftpack.py index 78cf214d2..8dc3eccbc 100644 --- a/numpy/fft/fftpack.py +++ b/numpy/fft/fftpack.py @@ -55,12 +55,13 @@ def _raw_fft(a, n=None, axis=-1, init_function=fftpack.cffti, raise ValueError("Invalid number of FFT data points (%d) specified." % n) - try: - # Thread-safety note: We rely on list.pop() here to atomically - # retrieve-and-remove a wsave from the cache. This ensures that no - # other thread can get the same wsave while we're using it. - wsave = fft_cache.setdefault(n, []).pop() - except (IndexError): + # We have to ensure that only a single thread can access a wsave array + # at any given time. Thus we remove it from the cache and insert it + # again after it has been used. Multiple threads might create multiple + # copies of the wsave array. This is intentional and a limitation of + # the current C code. + wsave = fft_cache.pop_twiddle_factors(n) + if wsave is None: wsave = init_function(n) if a.shape[axis] != n: @@ -86,7 +87,7 @@ def _raw_fft(a, n=None, axis=-1, init_function=fftpack.cffti, # As soon as we put wsave back into the cache, another thread could pick it # up and start using it, so we must not do this until after we're # completely done using it ourselves. - fft_cache[n].append(wsave) + fft_cache.put_twiddle_factors(n, wsave) return r |