Skip to content

Commit c5036df

Browse files
committed
non-reentrant trylock in maybe_destroy_plan
1 parent 8c239bb commit c5036df

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/fft.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ unsafe_destroy_plan(plan::FFTWPlan{<:fftwSingle}) =
275275
const deferred_destroy_lock = ReentrantLock() # lock protecting the deferred_destroy_plans list
276276
const 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+
278282
function 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

0 commit comments

Comments
 (0)