可能是没有重新对新文件进行编译
更改一个进程所能创建的最大进程数之前
更改一个进程所能创建的最大进程数之后
测试代码 文章来源:https://uudwc.com/A/zkE95
#include <iostream>
#include <unistd.h>
#include <sys/wait.h>
#include <string.h>
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
using namespace std;
void *func(void *argv)
{
// cout << "i am a new pthread, my tid is" << pthread_self() << endl;
while (1)
{
}
}
int main()
{
cout << "i am main pthread" << endl
<< "my tid is " << pthread_self() << endl;
// pthread_t 不能用数组吗,应该是可以的,但是我此前实验代码有错误
// pthread_t tid;
int count = 0; // 计算创建了多少个线程
for (int i = 0; i < 100000000000000000000; i++)
{
int ret = 0;
pthread_t *pt = new pthread_t;
count++;
if (count % 100 == 0)
{
cout << count << endl;
}
// cout << "i am main pthread" << endl
// << "my tid is " << pthread_self() << endl;//
// sleep(1);
if (int ret = pthread_create(pt, NULL, func, NULL) != 0)
{
fprintf(stderr, "pthread_create : %s\n", strerror(ret));
exit(EXIT_FAILURE);
}
}
int ret = 3;
fprintf(stderr, "pthread_create : %s\n", strerror(ret));
for (;;)
{
cout << "i am main pthread" << endl;
sleep(1);
}
}
文章来源地址https://uudwc.com/A/zkE95