• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • Last Modified:

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 ?
0
checkin
Asked:
checkin
  • 2
1 Solution
 
helverCommented:
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.
0
 
checkinAuthor Commented:
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.
0
 
helverCommented:
So does that qualify as an acceptable answer?
0

Featured Post

Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now