Link to home
Start Free TrialLog in
Avatar of checkin
checkin

asked on

Pthreads

Hi !

I am trying to use pthreads on Solaris.
I can create a thread that runs sucessfully and from the calling function I issue a pthread_join which returns a success.  The problem I have is that while monitoring the memory usage of the process using the top program when the thread is created I see the memory jump up but when the join is issued the memory does not decrease.
I am planning to write a server that will have multiple threads and until I can sort out this issue I can not continue.  Does anybody know where I am going wrong ?
Avatar of helver
helver

What you're seeing is virtual memory usage, not physical memory usage.  Any time a process requests more memory (using malloc or something similar) and it must expand its used virtually memory, it will maintain this new size until the process dies.  Even though memory malloc'd is eventually freed (thus freeing up physical memory) the size of the process does not decrease.  However, the next time a similar malloc is issued, the process size should not have to increase.

One way to test this would be to spawn off a thread, have it rejoin, then spawn another.  The process size should remain the same as if only one thread had been spawned.  So essentially your process size should expand to the accomodate the memory requirements of the largest number of concurrent threads that you had supported up to the current time.  Your actual memory usage, however, could be much lower.
Avatar of checkin

ASKER

Hi !

Yes I found this too after doing some testing.  I ran 2000 threads at one go and then joined them all, I did see the memeory usuage drop.  The problem is that Solaris only releases resources back if some other process requires it, thats why with just one or two threads I did not see the memory decrease.
ASKER CERTIFIED SOLUTION
Avatar of helver
helver

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial