|
系统:kernel2.6 nptl
[PHP]#include <stdio.h>
#include <pthread.h>
void *thread_routine(void *arg)
{
// printf("hello world");
}
int main(int argc,char *argv[])
{
pthread_t thread_id;
void *thread_result;
int status;
int i=0;
int nsuss=0;
for(i=0;i<500;i++)
{
status=pthread_create(&thread_id,NULL,thread_routine,NULL);
if(status != 0)
{
perror("create thread");
return 0;
}
else
{
printf("create suss:%d",nsuss++);
}
}
while(1)
sleep(100);
}
[/PHP]
到380左右就出现Cannot allocate memory错误
是否是系统问题?
如何使其能创建上1k个线程?
谢谢了! |
|