multithreading - Should implementations of java.util.Comparator.compare(T o1, T o2) be thread safe? -


or should care when used in parallel implementations java.util.arrays.parallelsort(t[] a, comparator<? super t> cmp) ?

the comparison method nature pure function evaluated against objects may considered immutable @ least during sorting operation. mutating objects during sorting break essential assumption of sorting algorithm, order imposed comparator stable throughout operation.

the above implies that, although comparator must thread-safe when used in parallel sort, given no special effort. on flip side, need make sure doesn't contain thread-unsafe code 1 reason or another, such using thread-unsafe collaborator instance shared across invocations of compare().


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -