The sort function may invoke the following element access functions:
Operations of the random-access iterator of the actual template argument
(as per [random.access.iterators]),
as implied by the name of the template parameter RandomAccessIterator.
The swap function on the elements of the sequence
(as per the preconditions specified in [sort]).
A standard library function is vectorization-unsafe
if it is specified to synchronize with another function invocation, or
another function invocation is specified to synchronize with it,
and if it is not a memory allocation or deallocation function.
Implementations must ensure that internal synchronization
inside standard library functions does not prevent forward progress
when those functions are executed by threads of execution
with weakly parallel forward progress guarantees.
int x =0;
std::mutex m;
void f(){int a[]={1,2};
std::for_each(std::execution::par_unseq, std::begin(a), std::end(a), [&](int){
std::lock_guard<mutex> guard(m); // incorrect: lock_guard constructor calls m.lock()++x;
});
}
The above program may result in two consecutive calls to m.lock()
on the same thread of execution (which may deadlock),
because the applications of the function object are not guaranteed
to run on different threads of execution.