最近,在做一个关于聊天服务器的项目,其中遇到了一个问题,那就是一个进程可以产生多少个线程呢?
开始各种想象,会和不同平台,不同系统相关,网上很多大佬说是1024个,也有256个。
与其无端猜测,不如动手测试一下。在Linux32位平台,进行测试。
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <iostream>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <pthread.h>
7 #include <errno.h>
8
9 using namespace std;
10 //测试一个进程可以启动多少个线程???
11
12 void *thread_function(void *arg);
13
14 char message[] = "Hello world";
15
16 int main()
17 {
18 int res;
19 pthread_t a_thread;
20 int i = 0;
21
22 while( 1 )
23 {
24 //创建线程
25 res = pthread_create(&a_thread, NULL, thread_function, (void *)messa ge);
26 i++;
27