免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 13042 | 回复: 18
打印 上一主题 下一主题

[函数] 请教高人,关于线程优先级的问题 pthread_attr_setschedpolicy [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-06-02 23:13 |只看该作者 |倒序浏览
pthread_attr_t  attr;
        int pocily;
        int ret;   

        pthread_attr_init(&attr);
        if (ret =pthread_attr_setschedpolicy(&attr, SCHED_FIFO)) {
                printf("set ched policy failed --  %s \n", strerror(ret));
                return -1;
        }

        if (pthread_attr_getschedpolicy(&attr, &pocily)) {
                printf("set ched policy failed --  %s \n", strerror(ret));
                return -1;
        }
         
        if (pocily == SCHED_FIFO) {
                printf(" fifo .\n");
        } else if (pocily ==  SCHED_RR) {
                printf(" rr.\n");
        } else if (pocily ==  SCHED_OTHER) {
                printf("other.\n");
        } else {
                printf("unkown.\n");
        }


我想更改一个线程的优先级; 上述代码都在超级用户下运行的,

1.  上面这段代码在我的FC7 (kernel 2.6.21)下面运行, 得到的pocily 不是SCHED_FIFO\SCHED_RR \ SCHED_OTHER中的任何一个,而是一个随机数,(也就是输出"unknown"), 这是为什么? 看样子pthread_attr_getschedpolicy没有正常工作,但是调用又没有失败。

2.把这段代码放到 arm-linux 2.6.21intel xscale monahans pxa310 平台下运行,无论用pthread_attr_setschedpolicy怎么设置,最后得到
的pocliy 都是SCHED_OTHER,  然后用 sched_get_priority_max(pocliy) 得到为0;
是不是我这个内核不支持SCHED_FIFO或者SCHED_RR呀? 那我要怎么改呢?
如果要重编内核的话,改内核选项中的哪一项?

我强烈需要更改我程序中一个线程的优先级,先谢谢了。

[ 本帖最后由 makeclear 于 2008-6-2 23:16 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2008-06-03 00:39 |只看该作者

回复 #1 makeclear 的帖子

不能沉,急用。

论坛徽章:
0
3 [报告]
发表于 2008-06-03 10:11 |只看该作者
再顶

论坛徽章:
0
4 [报告]
发表于 2008-06-03 12:17 |只看该作者
我的第一贴竟如此凄惨.................... 让我怀疑这论坛有高人吗?

论坛徽章:
0
5 [报告]
发表于 2008-06-03 14:47 |只看该作者
高人快现身,不能沉。

[ 本帖最后由 makeclear 于 2008-6-3 14:51 编辑 ]

论坛徽章:
0
6 [报告]
发表于 2008-06-03 15:39 |只看该作者
redhat AS 5上试验是fifo .

论坛徽章:
0
7 [报告]
发表于 2008-06-03 17:00 |只看该作者
试一下memset(&attr,0,sizeof(pthread_attr_t));

再看看下面的拓展一下思路,google的
SCHED_SOPRADIC is certainly not an additional thread. It is one of several scheduling policies that affect the behavior of the scheduler. The scheduler is part of the kernel and you may be using the term dispatcher instead. Which term you use is not important as long as you understand that the scheduler adjusts the priorities of the threads as well as finding one to run in an available cpu. See this link: Thttp://www.qnx.com/developers/do ... Sporadic_scheduling
which has the best description I have seen on sporadic scheduling.

论坛徽章:
0
8 [报告]
发表于 2008-06-03 17:52 |只看该作者
原帖由 cuinantrue 于 2008-6-3 17:00 发表
试一下memset(&attr,0,sizeof(pthread_attr_t));

再看看下面的拓展一下思路,google的
SCHED_SOPRADIC is certainly not an additional thread. It is one of several scheduling policies that affect th ...



试了,不行,问题依旧

论坛徽章:
0
9 [报告]
发表于 2008-06-03 18:11 |只看该作者
应该是和你编译的方式有关。
我在自己的机器上面试的:
gcc test.c -o test 这样的话结果就为unknown
gcc test.c -o test -lpthread 这样的话结果就为fifo

论坛徽章:
0
10 [报告]
发表于 2008-06-03 18:14 |只看该作者
原帖由 scutan 于 2008-6-3 18:11 发表
应该是和你编译的方式有关。
我在自己的机器上面试的:
gcc test.c -o test 这样的话结果就为unknown
gcc test.c -o test -lpthread 这样的话结果就为fifo




高人啊,高人。。。。。。。。 链接和不链接还有区别吗?  不用pthread库也没有报链接错误啊? 崩溃了。。。。。。。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP