当前位置: 技术问答>linux和unix
Linux下有关posix的问题
来源: 互联网 发布时间:2017-04-17
本文导语: 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_...
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 = %dn",status);
}
status = pthread_create(&thread_id2,&my_attr2,child_process2,NULL);
if(status != 0)
{
printf("Create thread2 error,status = %dn",status);
}
#endif
pthread_join(thread_id,NULL);
pthread_join(thread_id2,NULL);
运行之后,始终报错,也就是pthred_create返回值为22
我的代码如下:
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 = %dn",status);
}
status = pthread_create(&thread_id2,&my_attr2,child_process2,NULL);
if(status != 0)
{
printf("Create thread2 error,status = %dn",status);
}
#endif
pthread_join(thread_id,NULL);
pthread_join(thread_id2,NULL);
运行之后,始终报错,也就是pthred_create返回值为22
|
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
resource limit (set via setrlimit(2)), which limits the number
of process for a real user ID, was reached; or the kernel's
system-wide limit on the number of threads,
/proc/sys/kernel/threads-max, was reached.
EINVAL Invalid settings in attr.
EPERM No permission to set the scheduling policy and parameters
specified in attr.
|
可能pthread库有问题,updata一下在试试