make the queue thread-safe