c++ - `std::sort()` 是否使用线程来提高其性能?

标签 c++ multithreading sorting stl

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/

相关文章:

C++ Kinect v2 & freenect2 : how to convert depth data to real world coordinates

c++ - 如何将值中对象的属性更改为映射

c++ - ICC 中的 -O3 搞乱了内在函数,与 -O1 或 -O2 或相应的手动组装一起使用

c++ - 如何在 C++ Autotools 项目中禁用 C 编译器

c++ - QTextStream 在 QThread::sleep() 之前不写入

android - android相机和线程安全问题

sorting - Cassandra如何按时间戳排序

c - 数学。排序。 "n * (n + 1)/2"总是小于 "n * n"吗?

c# - C# 中基于另一个浮点列表的排序列表

Java - 阻止 GSON 创建一个额外的线程