一个进程最大多少线程

  • Ubuntu64位
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>


void* thread_func(void* arg)
{
	//printf("线程序号:%d\n", *((int*)arg));
	while(1){};
}

int main()
{
	unsigned int count = 0;
	while(1)
	{
		pthread_t t;
		//int i = 0;
		if( 0 == pthread_create(&t, NULL, thread_func, NULL) )
		{
			printf("成功创建第%d个线程\n", ++count);
			continue;
		}
		else {
			printf("最大线程数:%d\n", count);
			break;
		}
	}
	return 0;
}

运行三次,分别是3004,6969,9971。
第四次,在7000多个之后,一次会打印多行//为什么没有每次只输出一行呢,每次卡几秒输出可以理解,但每次会输出多行,怎么解释?

posted @ 2022-03-13 19:25  llovewhat  阅读(89)  评论(0)    收藏  举报