Tag: thread priority

无法设置Pthread优先级

我无法使用pthread_attr_setschedparam()设置Pthread优先级。 我试图解决这个问题,但无法解决。 我还咨询了我的教科书,该教科书也使用相同的function。 我从书中复制了这段代码。 你能告诉我如何设置线程优先级吗? 这是代码: void *Func(void *arg); int main() { pthread_t tid[5]; pthread_attr_t *tattr; struct sched_param param; int pr,error,i; do { if( (tattr=(pthread_attr_t *)malloc(sizeof(pthread_attr_t)) )==NULL) { printf(“Couldn’t allocate memory for attribute object\n”); } }while(tattr==NULL); if(error=pthread_attr_init(tattr)) { fprintf(stderr,”Attribute initialization failed with error %s\n”,strerror(error)); } for(i=0;i<5;i++) { //scanf("%d",&pr); error = pthread_attr_getschedparam(tattr,&param); if(error!=0) { printf("failed to […]

android上的pthread_create警告

在调用pthread_create函数后,我收到下一条消息: W / libc(26409):pthread_create sched_setscheduler调用失败:不允许操作 用于创建线程的代码是: pthread_attr_t threadAttr; int ret = pthread_attr_init(&threadAttr); //code to check ret – it’s 0 size_t guard_size = 0; pthread_attr_getguardsize(&threadAttr, &guard_size); ret = pthread_attr_setstacksize(&threadAttr, myStackSize + guard_size); //code to check ret – it’s 0 ret = pthread_attr_setdetachstate(&threadAttr, PTHREAD_CREATE_DETACHED); //code to check ret – it’s 0 ret = pthread_attr_setschedpolicy(&threadAttr, SCHED_FIFO); //code to […]