Monday, February 21, 2011

Regarding the deallocation of memory resources of a thread

Hi,

I was going through the man pages of pthread_join and its mentioned the following

"When a joinable thread terminates, its memory resources (thread descriptor and stack) are not deallocated until another thread performs pthread_join on it. Therefore, pthread_join must be called once for each joinable thread created to avoid memory leaks."

The reason has for doing this has been mentioned as to avoid memory leaks. But, I am not sure why in the first place the resources for a particular thread need to be still kept upon its termination.

Jayaraj

From stackoverflow
  • The thread descriptor is kept around so the thread procedure return value could be retrieved through the second parameter of pthread_join(2). This is the same idea as with zombie processes.

    Keeping the stack of terminated thread was probably a requirement of the particular thread library implementation at the time the API was formalized.

0 comments:

Post a Comment