Fix deadlock detection code