make the priority queue implementation thread safe