tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Possible pthreads memory leak

On Sat, 16 Jan 2010 23:32:35 -0600
Zach Wegner <> wrote:

> On Sat, Jan 16, 2010 at 10:28 PM, john heasley <> 
> wrote:
> >
> > i think threads are attacahed by default, so you need to free the thread
> > pointer ,etc. Âpthread_destory()
> Hello John,
> I guess you mean pthread_detach()? I never thought that that was
> needed, and reading the man pages suggests that it's equivalent to a
> non-blocking version of pthread_join. So pthread_join should
> theoretically do the same cleanup that pthread_detach does, after the
> child thread exits. And indeed, calling pthread_detach after
> pthread_join (or vice versa) still leaks memory. pthread_detach
> returns an error too (ESRCH), as I guess it should.

You're right, you shouldn't need to detach threads which you're joining
(you'd indeed be leaking resources if you didn't join non-detached
threads, however).

I ran the same test on a recent i386 netbsd-5 and the process initially
grows (I suspect the pthread library, and potentially the heap memory
allocator, caches some pages/objects for performance), and then seems
rather stable in size.  I however do see a slight size increase over
time if running it for a long while.  However I'm still looking at the
new size and it appears stable again at 19M/904K SIZE/RES.


Home | Main Index | Thread Index | Old Index