make priority queue thread-safe