pthreads virtual memory usage -- memory is not freed after thread exit
Hi,
I have a program which creates 100 threads(joinable threads) and calls pthread_join on them.
But I found that the memory is not coming back to initial value after the threads are created and destroyed .
I tried my program in FC3 and CentOS 5.2 (same behaviour is seen in both OS's).
Please find my program below
#include <stdio.h>
#include <iostream.h>
#include <unistd.h>
bool bShutDown = false;
#define TRD_CNT 100
#define LPVOID void*
void* do_infinite(LPVOID tmp)
{
while(true)
{
sleep(10);
if(bShutDown)
break;
}
return NULL;
}
int main(int argc, char* argv[])
{
int k;
cout<<"press any key"<<endl;
cin>>k;
{
{
pthread_t thrd[TRD_CNT];
for(int i = 0 ; i < TRD_CNT ; ++i )
{
unsigned long id;
int idt = pthread_create(&thrd[i],0,do_infinite,0);
cout<<idt <<endl;
}
cout<<"press any key"<<endl;
cin>>k;
bShutDown = true;
for(int i = 0 ; i < TRD_CNT ; ++i )
{
pthread_join(thrd[i],NULL);
}
}
}
cout<<"press any key"<<endl;
cin>>k;
cin>>k;
return 1;
}
Before thread creation
VIRTUAL MEM 2376 KB
RES 836 KB
SHR 728 KB
while threads were running
VIRTUAL MEM 1002mm
RES 1368 KB
SHR 844 KB
After threads were joined
VIRTUAL MEM 33244 KB
RES 992 KB
SHR 856 KB
Values are from top command output..
Please Can somebody explain this behaviour.
Thanks
Mini
|