给定- 线程的线程 ID。
要求- 设置线程 id 的 Linux 优先级。
约束- 不能使用 setpriority()
我试过在下面使用
pthread_setschedprio (pthread_t thread, int prio);
pthread_setschedparam(pthread_t 线程,int 策略,const struct sched_param *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] 删除。
我来说两句