C++ & boost::threads - 如何根据工作类型确定线程的优先级?

标签 c++ boost

我在 Linux 上使用带有 boost 的 C++。

根据工作类型确定线程优先级的最佳方法是什么? 是否可以在 POSIX/pthread/Linux 中改变线程优先级?

最佳答案

据我所知,boost 不提供执行此操作的 API(C++11 标准肯定至少不提供)。

在 Linux 上,您可以 nicesetpriority每个线程独立于其他线程。但是请注意,这符合 POSIX 标准:

According to POSIX, the nice value is a per-process setting. However, under the current Linux/NPTL implementation of POSIX threads, the nice value is a per-thread attribute: different threads in the same process can have different nice values. Portable applications should avoid relying on the Linux behavior, which may be made standards conformant in the future.

因为 Linux 使用 pthreads(boost 的 Linux 端口也是如此)你也可以使用 pthread_setschedparam它的优点是比 Linux 特定的每线程 nice 行为更具可移植性。

在这两种情况下,由于必须求助于系统设施以管理所谓的“不透明”boost(或 C++11 中的 std),因此存在轻微的不安) 资源,因此请谨慎行事(与任何特定于实现的事物一样)。

关于C++ & boost::threads - 如何根据工作类型确定线程的优先级?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19611457/

相关文章:

c++ - boost序列化实际上是如何保存const对象的

c++ - 为什么 BOOST_FOREACH 有时不能用于 C++ 字符串?

c++ - 如何使用 C++ 在结构中的堆内存中定义变量?

c++ - 程序自行删除,不启动

c++ - 在 mac 上使用 macport 安装时,boost 库的默认位置是什么?

C++/Boost 文件系统 - 检测到 '_MSC_VER' 不匹配 : value '1700' doesn't match value '1600'

c++ - Boost Graph - 同时使用有向边和无向边

c++ - 如何使用 std::copy 打印用户定义的类型

c++ - .begin() 和 .end() 上未解析的标识符?

c++ - openCV/图像处理中创建 MAT 类型的 3 维数组时出现段错误