pthread的问题

makefile 2001-09-19 10:31:26
分少,但第一个答对的必给。
为什么pthread_create 到一定的数目时就不能建立线程了,尽管线程已经退出。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
static int num=0;
void *start(void *da)
{
printf("[%d]\n",num++);
return NULL;
}
int main()
{
pthread_t id;
int r;
while(1)
if ((r=pthread_create(&id,NULL,start,NULL))!=0)
break;
else
sleep(1);
perror("create pthread");
printf("[%d]\n",r);
}

[1017]
[1018]
[1019]
[1020]
[1021]
create pthread: Interrupted system call
[11]
如何能不休止的create线程2
...全文
75 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
www_com_me 2002-01-09
  • 打赏
  • 举报
回复
伙计们,我怎末不能#include <pthread.h>

Last_Dodo 2002-01-08
  • 打赏
  • 举报
回复
Try use following code to add attribute, it should get you through:
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
...pthread_create(&id,&attr,start,NULL)...
peifang 2002-01-08
  • 打赏
  • 举报
回复
你的线程即没有join也没有detach,等于是没有退出。
lovec 2002-01-08
  • 打赏
  • 举报
回复
The symbol PTHREAD_THREADS_MAX may ALSO be defined, to the true limit
allowed by the system
POSIX specifies two compile-time constants, in , for each
runtime limit. One is the MINIMUM value of that MAXIMUM which is
required to conform to the standard.

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧