线程属性(优先级):pthread_attr_t

来源:互联网 发布:spss数据差异性分析 编辑:程序博客网 时间:2024/05/29 14:43

一、代码

        pthread_attr_t 

        pthread_attr_init()、pthread_attr_destroy()

        pthread_attr_setinheritsched()

        pthread_attr_setschedpolicy()

        pthread_attr_setschedparam()

        pthread_getschedparam()

#include <stdlib.h>#include <stdio.h>#include <pthread.h>void* thread_proc(void* arg){        int policy;        struct sched_param param;        //        pthread_getschedparam(pthread_self(), &policy, ¶m);        printf("thread policy:%d, param.sched_priority:%d\n", policy, param.sched_priority);        return NULL;}int main(int argc, char*argv[]){        pthread_t tid;        pthread_attr_t attr;        //        pthread_attr_init(&attr);        //        int inher = PTHREAD_EXPLICIT_SCHED;        pthread_attr_setinheritsched(&attr, inher);        //              int policy = SCHED_FIFO;        pthread_attr_setschedpolicy(&attr, policy);        //        struct sched_param param;        param.sched_priority = 30;        pthread_attr_setschedparam(&attr, ¶m);        pthread_create(&tid, &attr, thread_proc, NULL);        pthread_join(tid, NULL);        //        pthread_attr_destroy(&attr);        return 0;}

二、运行结果



参考资料

        linux线程的优先级设置:http://blog.csdn.net/lanseshenhua/article/details/5524797

0 0
原创粉丝点击