Fix deadlock when calling queue.put() while holding the mutex.