Skip to content

Commit

Permalink
uses a spintest to avoid task switches in finalizers (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Aug 20, 2020
1 parent 5200ded commit 7d8a206
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/fft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,11 @@ function maybe_destroy_plan(plan::FFTWPlan)
# need to acquire deferred_destroy_lock before trylock to avoid a memory leak
# (race to avoid: trylock == false, other thread unlocks and calls destroy_deferred,
# then we push a deferred plan that may never get freed)
lock(deferred_destroy_lock)
# Also, we need to use a trylock spinloop rather than lock(deferred_destroy_lock),
# since task switches aren't permitted in finalizers. This has suboptimal efficiency,
# but we shouldn't waste too many cycles since destroying plans is quick and contention
# should be rare.
while !trylock(deferred_destroy_lock); end
try
# note: fftwlock is re-entrant, so trylock will succeed here if we
# are in the task that holds the planner lock. That's okay — 
Expand Down

0 comments on commit 7d8a206

Please sign in to comment.