Date: Sat, 21 Feb 2015 15:37:20 -0600 From: Matthew Grooms <mgrooms@shrew.net> To: freebsd-stable@freebsd.org Subject: Re: pthread leaky with resources? Message-ID: <54E8FA90.8080102@shrew.net> In-Reply-To: <20150221083444.5759b1d8@B85M-HD3-0.alogt.com> References: <54E65E05.2040101@shrew.net> <20150220100446.GL34251@kib.kiev.ua> <54E74D17.6020209@shrew.net> <Pine.GSO.4.64.1502201010580.16244@sea.ntplx.net> <54E75087.7080100@shrew.net> <20150221083444.5759b1d8@B85M-HD3-0.alogt.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2/20/2015 6:34 PM, Erich Dollansky wrote: > Hi, > > On Fri, 20 Feb 2015 09:19:35 -0600 > Matthew Grooms <mgrooms@shrew.net> wrote: > >>> When a thread is created, it will first try to reuse cached >>> resources before allocating new resources. >>> >>> If you are creating 200 threads, for instance, try destroying those >>> 200 threads, then create 200 new threads. You shouldn't see much >>> change in resources, as libpthread should use the cached >>> resources. If you see a double in the amount of resources used, >>> then that would seem like a bug. >>> >> Thanks for the response. Let me do some more testing. I know that OS >> developer time is a precious resource. If I can find more evidence of >> the problem I will present it. >> > I am currently also working on a multi threaded program and have had > also a problem like this. I thought it was an error 100% on my side. As > I also did at the same time an upgrade to > > 10.1-STABLE FreeBSD 10.1-STABLE #2 r276328 > > it could be that there was really some problem in a library. > > Some of the threads just return while others are cancelled. If you have > cancelled threads, do you use pthread_cleanup_push and > pthread_cleanup_pop? > Hi Erich, Thanks for the response. I don't use pthread_cancel. The threads I'm creating either join or are detached at creation time. After reading the explanation from Daniel, things make a lot more sense with respect to what I was seeing with the resource utilization in my test program. After spending another day looking at the code, I found the resource leak. Some of the threads were not being detached properly which lead to the increased memory utilization. Everything appears to be fine now after running for about 16 hours. Thanks to everyone for the useful feedback. Since I'm rambling on in public about pthreads on FreeBSD, I think it would be useful for the pthread_join manual page to be a bit more clear about the following statement ... A thread that has exited but remains unjoined counts against [_POSIX_THREAD_THREADS_MAX]. ... I assume that's only true if a thread is left in a joinable state. Thanks, -Matthew
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?54E8FA90.8080102>