pthread_create and priorities pthread_attr_setschedparam

pthread_create and priorities


I want to start up a pthread with a given priority. The documentation seems
clear enough, however, the code I wrote doesn't work. The thread always
starts with a default priority. I can use a similar procedure within the
thread to adjust priority and that works. What have I overlooked? I am
running DLL 1.3.2 on Win NT (Patch 5.0, I believe).

THE CODE:
******** FILE: schedTest.c ******************

#include <pthread.h>

char *sched_type[] = {
"SCHED_OTHER",
"SCHED_FIFO",
"SCHED_RR"
};

void pthread_info(void){
pthread_t thread;
struct sched_param sp;
int type;
int rc;
thread = pthread_self();
rc=pthread_getschedparam(thread, &type, &sp);
printf("Thread id:%x %s Priority Max:%d, Current:%d, Min:%d/n",
thread,
sched_type[type],
sched_get_priority_max(type),
sp.sched_priority,
sched_get_priority_min(type));
}

pthread_t t1;
void mytest(void) {
puts("Mytest1");
/*print thread info*/
pthread_info();
}


int main(void) {
pthread_attr_t attr;
struct sched_param parm;
puts("Hello world!");
pthread_attr_init(&attr);
parm.sched_priority=-3;
pthread_attr_setschedpolicy(&attr,SCHED_FIFO);
pthread_attr_setschedparam(&attr,&parm);
pthread_create(&t1, &attr, (void *) mytest, NULL);
puts("That's all folks");
pthread_join(t1,NULL);
return 0;
}

THE OUTPUT:
**************************
Administrator@OLE300GL /home/testy/FW_test
$ gcc schedTest.c

Administrator@OLE300GL /home/testy/FW_test
$ a
Hello world!
That's all folks
Mytest1
Thread id:a010500 SCHED_FIFO Priority Max:-14, Current:0, Min:15
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值