替代 setpriority(PRIO_PROCESS, thread_id, priority)

用户2618142

给定- 线程的线程 ID。
要求- 设置线程 id 的 Linux 优先级。
约束- 不能使用 setpriority()

我试过在下面使用

pthread_setschedprio (pthread_t thread, int prio);
pthread_setschedparam(pthread_t 线程,int 策略,const struct sched_pa​​ram *param);

以上两个 API 都使用 pthread_t 作为参数。我无法从线程 id 构造(类型转换)pthread_t。我知道由于不同的类型,转换这是不可能的。

有没有办法仍然做到这一点?

弗洛里安·韦默

pthread_setschedprio接口的某些方面可用于带有sched_setparam函数的普通线程 ID (在 中声明<thread.h>)。sched_setparam手册页说,过程受到影响(这是POSIX授权的行为),但在Linux上,它实际上是该ID的线程

请记住,sched_setparam直接调用可能会破坏 PI 互斥体和其他同步原语的预期行为,因为直接调用不执行pthread_* 函数执行的额外簿记

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章