日期:2014-05-16  浏览次数:20667 次

Linux下有关posix的问题
1.今天在debian下写posix代码,遇到了一下 一个问题,实在无法解决,望高手帮解决一下,谢谢。
我的代码如下:
pthread_attr_t my_attr,my_attr2;

#if defined(_POSIX_THREAD_PRIORITY_SCHEDULING)
pthread_attr_init(&my_attr);
pthread_attr_init(&my_attr2);

my_param.__sched_priority = 10;
my_param2.__sched_priority = 15;

pthread_attr_setschedparam(&my_attr,&my_param);
pthread_attr_setschedparam(&my_attr2,&my_param2);

pthread_attr_setinheritsched(&my_attr,PTHREAD_EXPLICIT_SCHED);
pthread_attr_setinheritsched(&my_attr2,PTHREAD_EXPLICIT_SCHED);

pthread_attr_setschedpolicy(&my_attr,SCHED_RR);
pthread_attr_setschedpolicy(&my_attr2,SCHED_RR);

status = pthread_create(&thread_id,&my_attr,child_process1,NULL);
if(status != 0)
{
printf("Create thread1 error,status = %d\n",status);
}

status = pthread_create(&thread_id2,&my_attr2,child_process2,NULL);
if(status != 0)
{
printf("Create thread2 error,status = %d\n",status);
}

#endif
pthread_join(thread_id,NULL);
pthread_join(thread_id2,NULL);

 运行之后,始终报错,也就是pthred_create返回值为22
linux?posix?pthread 线程

------解决方案--------------------
可能pthread库有问题,updata一下在试试
------解决方案--------------------
RETURN VALUE         top

       On success, pthread_create() returns 0; on error, it returns an error
       number, and the contents of *thread are undefined.
ERRORS         top

       EAGAIN Insufficient resources to create another thread, or a system-
              imposed limit on the number of threads was encountered.  The
              latter case may occur in two ways: the RLIMIT_NPROC soft