Second attempt at thread deadlock fix.