Correct a thread deadlock related to indexing and other threads