作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
刚开始接触pthreads,了解不多。我试图使用 pthread_setschedprio() 设置 pthreads 的优先级,但它返回“EINVAL”。这是我的代码:
#include <pthread.h>
#include <errno.h>
void *Run(void *ptr);
class Thread {
public:
pthread_t myPthread;
void start() {
pthread_create( &myPthread, NULL, Run, (void*)this );
}
Thread() { }
virtual void run() = 0;
};
void *Run( void *ptr ) {
Thread* tmp;
tmp = (Thread*)ptr;
tmp->run();
}
class MyThread : public Thread {
public:
virtual void run() {
while (1) {
printf("Running\n");
sleep(1);
}
}
};
MyThread t1;
int main()
{
int status;
t1.start();
status= pthread_setschedprio(t1.myPthread, 300);
if(status!=0)
{
if(status==EPERM)
{
fprintf(stderr,"EPERM\n");
}
else if(status==EINVAL)
{
fprintf(stderr,"EINVAL\n");
}
else
{
fprintf(stderr,"neither EPERM nor EINVAL\n");
}
fprintf(stderr,"error %d\n",status);
errno=status;
perror("");
exit(1);
}
pthread_join( t1.myPthread, NULL);
exit(0);
}
当我尝试编译它时,我得到EINVAL运行错误 22无效参数
谁能告诉我为什么会出现错误以及如何解决?
最佳答案
来自 this链接 它看起来意味着您指定的优先级对于当前调度策略无效。如果你看this页面,您可以确定不同调度策略的有效优先级。最后,如果您不确定,可以使用 pthread_getschedparam 来确定您正在使用的当前调度策略。
关于c++ - pthread_setschedprio() 失败,返回 "EINVAL",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3140505/
刚开始接触pthreads,了解不多。我试图使用 pthread_setschedprio() 设置 pthreads 的优先级,但它返回“EINVAL”。这是我的代码: #include #inc
我是一名优秀的程序员,十分优秀!