b r a y d e n . o r g / Software

/ WebHome / ProjectPages / PthreadWin32

This Web


WebHome  
Topic List  
Web Statistics 

All Webs


Books
Main
Random
Software
TWiki  

brayden.org


Home
Monthly Digest
Today's Links
Resumé
Reading List
Books RSS
Random RSS
Software RSS

Other


Dale's Blog

currently-reading
TextDrive

Information, links, and notes about the pthreads-win32 library

pthreads-win32

Memory leak

UPDATE - I wrote a little test program to create many threads, each with allocated storage passed into the thread function and also allocated storage from within the thread function. It does not leak memory. If there's a leak in the pthreads library it is not related to pthread_create() and thread destruction.

...

I've run into a memory leak that I think must be inside pthreads-win32. I've convinced myself that the leak is not elsewhere in my application. A quick google search reveals the following:

As far as I can tell without digging into the source, pthreads-win32 calls beginthreadex from inside pthread_create(). Here's a snippet from MSDN :

You can call _endthread or _endthreadex explicitly to terminate a thread; however, _endthread or _endthreadex is called automatically when the thread returns from the routine passed as a parameter. Terminating a thread with a call to endthread or _endthreadex helps to ensure proper recovery of resources allocated for the thread.

_endthread automatically closes the thread handle (whereas _endthreadex does not). Therefore, when using _beginthread and _endthread, do not explicitly close the thread handle by calling the Win32CloseHandle API. This behavior differs from the Win32ExitThread API.

Note For an executable file linked with LIB, do not call the Win32 ExitThread API; this prevents the run-time system from reclaiming allocated resources. _endthread and _endthreadex reclaim allocated thread resources and then call ExitThread.

I do not have a handle leak, so thread handles are being closed. But there does seem to be a significant memory leak. My application starts many short-lived threads.

-- DaleBrayden - 14 Oct 2003

 
 
Current Rev: r1.1 - 03 Dec 2005 - 15:56 GMT - DaleBrayden, Revision History:Diffs | r1.1
© 2003-2011 by the contributing authors.