What do I have to consider when using std::sort with a parallel execution policy?

Viewed 99

With C++17, we got Execution Policies. I am interested in the parallel policies

What do I have to consider when I use std::sort with a parallel policy? Unlike std::transform or std::for_each, std::sort accesses two elements at the same time. Do I have to take data races into consideration here?

1 Answers

There isn't anything extra to consider when calling std::sort with an execution policy. It is already UB for your compare to mutate the elements it is comparing.

The implementation is required to ensure there are no data races within any of the functions defined in std.

Related