File tree Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change @@ -275,6 +275,10 @@ unsafe_destroy_plan(plan::FFTWPlan{<:fftwSingle}) =
275275const deferred_destroy_lock = ReentrantLock () # lock protecting the deferred_destroy_plans list
276276const deferred_destroy_plans = FFTWPlan[]
277277
278+ # hack to get non-reentrant lock, which is necessary to prevent GC running in the
279+ # same task that acquired fftwlock to use deferred_destroy_plans in maybe_destroy_plan.
280+ trylock_nonreentrant (rl:: ReentrantLock ) = current_task () != = rl. locked_by && trylock (rl)
281+
278282function destroy_deferred ()
279283 try
280284 lock (deferred_destroy_lock)
@@ -302,7 +306,7 @@ function maybe_destroy_plan(plan::FFTWPlan)
302306 # (race to avoid: trylock == false, other thread unlocks and calls destroy_deferred,
303307 # then we push a deferred plan that may never get freed)
304308 lock (deferred_destroy_lock)
305- if trylock (fftwlock)
309+ if trylock_nonreentrant (fftwlock)
306310 try
307311 unsafe_destroy_plan (plan)
308312 finally
You can’t perform that action at this time.
0 commit comments