|
|

楼主 |
发表于 2005-11-10 14:18:04
|
显示全部楼层
再问一下。在RH9.0下。为什么在主线程中没办法设置发起线程的调度策略呢。代码如下:
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include <sched.h>
void * thread1(void *arg)
{
int i;
short j;
struct sched_param temp;
pthread_getschedparam(pthread_self(),&i,&temp);
if(i == SCHED_FIFO)
printf("the policy is fifo in 1\n");
printf("the prio is %d\n",temp.sched_priority);
printf("this is thread1\n");
return NULL;
}
int main(void)
{
pthread_t thread_1;
pthread_t thread_2;
pthread_attr_t thread_attr;
int thread_policy;
int i,j;
struct sched_param param;
void * result;
int status;
#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
status = pthread_attr_init(&thread_attr);
status = pthread_attr_setschedpolicy(&thread_attr,SCHED_RR);
if(status != 0)
printf("can't set policy fifo\n");
i = sched_get_priority_min(SCHED_RR);
j = sched_get_priority_max(SCHED_RR);
param.sched_priority = (i+j)/2;
status =pthread_attr_setschedparam(&thread_attr,¶m);
status = pthread_attr_setinheritsched(&thread_attr,PTHREAD_EXPLICIT_SCHED);
if(status != 0)
printf("can't set inheritsched\n");
#else
printf("can't set priority\n");
#endif
status = pthread_create(&thread_1,NULL,&thread1,NULL);
if(status != 0)
perror("create thread 1 err");
while(1);
pthread_exit(NULL);
return (1);
}
运行发现创建的线程的priority老是0,调度策略也不是FIFO。这是为什么,哪里错了??? |
|