I'm trying to use
queue = new ConcurrentSkipListSet<Task>(Comparators.comparing(Task::priority))
as a concurrent priority queue with unique elements (see a similar discussion here), but I need to change the priority of tasks from time to time.
Clearly to change the priority of elements while they're in the set is to open a can of worms; fortunately, I only need to change their priority after removing them from queue, and before resubmitting them. More precisely, I use pollFirst() to pop an element from the queue, which I may need to resubmit after updating its priority (with a lower priority).
If this was a serial implementation, there should be no problem with changing the priority of elements while they're outside of the set.
What's a thread-safe way of doing this update with concurrent access? Is it enough to guarantee that
task = queue.pollFirst() happens before task.priorityUpdate(), happens before queue.add(task)?