std::sort()
通常使用线程来提高其性能吗?我意识到这可能因实现而异。如果不是,为什么不呢?
最佳答案
[res.on.data.races]/8 Unless otherwise specified, C++ standard library functions shall perform all operations solely within the current thread if those operations have effects that are visible (4.7) to users.
/9 [ Note: This allows implementations to parallelize operations if there are no visible side effects. —end note ]
std::sort
原则上,可以在对基本类型的元素进行排序时使用并行执行(是否可以观察到),但不能使用用户定义的类型(当然,除非通过执行策略参数明确授予权限)。类型的 operator<
可能不是线程安全的。
关于c++ - `std::sort()` 是否使用线程来提高其性能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47707277/