23,121
社区成员
发帖
与我相关
我的任务
分享
#include<pthread.h>
#include<iostream>
#include<cstdlib>
using namespace std;
pthread_mutex_t fmx;
void* func(void *x)
{
int *p=(int*)x;
int **data=(int **)malloc((*p)*sizeof(int*));
for(int i=0;i<*p;i++)
{
data[i]=(int*)malloc((*p)*sizeof(int));
for(int j=0;j<*p;j++)
{
data[i][j]=j;
}
}
for(int i=0;i<*p;i++)
{
for(int j=0;j<*p;j++)
{
data[i][j]=data[i][j]*data[i][j];
}
}
for(int i=0;i<*p;i++)
{
free(data[i]);
data[i]=0;
}
free(data);
data=0;
}
int main()
{
int k=2000;
for(int i=0;i<10;i++)
{
pthread_t threadlist[2000];
for(int j=0;j<2000;j++)
{
pthread_create(&threadlist[i],NULL,func,&k);
}
for(int j=0;j<2000;j++)
{
void *r=0;
pthread_join(threadlist[i],&r);
}
cout<<"******************************************patch "<<i<<" over!"<<endl;
}
}
try{
}cache{
}
or
if((err=pthread_create(&threadlist[j],NULL,func,&k))!=0)
{
...
}
????
but I just want to know why the VIRT and DATA keep on growing after those relevant threads quit, I think those exception definition is not related to my purpose,I know my code is not that well, but this code is just for testing,
for(int j=0;j<2000;j++)
{
void *r=0;
pthread_join(threadlist[j],&r);
}
cout<<"******************************************patch "<<i<<" over!"<<endl;