LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 05-20-2009, 02:58 AM   #1
minimol
LQ Newbie
 
Registered: Aug 2006
Distribution: Fedora
Posts: 10

Rep: Reputation: 0
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
 
Old 05-21-2009, 02:18 AM   #2
Manjunath1847
Member
 
Registered: Mar 2007
Posts: 44

Rep: Reputation: 16
Minimol, one thing you can try is to put pthread_exit to make notify explicitly thread exit. Not sure if this help, but just can be tried out with minimal change.
 
Old 05-26-2009, 01:19 AM   #3
minimol
LQ Newbie
 
Registered: Aug 2006
Distribution: Fedora
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Manjunath1847 View Post
Minimol, one thing you can try is to put pthread_exit to make notify explicitly thread exit. Not sure if this help, but just can be tried out with minimal change.


I tried pthread_exit. There is no difference.

After doing a bit of googling I found some documents saying .. virtual memory is not always freed by the heap manager as it is considered as an inexpensive resource.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Virtual Memory Usage always reporting 100% - Fedora Core 3 rossx Linux - Server 6 08-15-2008 06:25 AM
How does the cdev_alloc memory get freed up? nabramovitz Linux - Kernel 2 03-28-2008 07:04 PM
Difference between resident memory,shared memory and virtual memory in system monitor mathimca05 Linux - Newbie 1 11-11-2007 04:05 AM
Virtual Memory usage redhatrosh Linux - Software 1 03-20-2005 01:22 AM
%CPU , Memory Usage, Thread count srinivasar Programming 0 09-20-2003 03:56 AM


All times are GMT -5. The time now is 09:53 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration