Fix a deadlock in `thread_pool`.