[Quickfix-developers] Re: QuickFix - Serious thread resources leak on Linux
Brought to you by:
orenmnero
|
From: Oren M. <ore...@ya...> - 2003-04-29 14:57:10
|
Thanks. This is something I did not know. I'll get
this change into source control.
--- Gene Gorokhovsky <mus...@ya...> wrote:
> I have discovered that every TCP/IP connection to my
> Linux ThreadedSocketAcceptor based server increases
> memory footprint by 4-8K which is not recovered once
> the connection closes. After some investigation I
> have
> found that this happens because
> ThreadedSocketAcceptor
> (and possibly other Threaded*) classes create
> joinable
> threads which exit when the socket closes without
> either pthread_join or pthread_detach called on
> them.
>
> On Linux POSIX Threads implementation it is
> insufficent to return from joinable thread because
> this does not release thread resources back, hence
> the
> leak. pthread_detach has to be used to explicitly
> clean-up when joinability is no longer necessary.
>
> On my build I have added the following to
> Utility.cpp
> void thread_detach(int thread)
> {
> #ifdef _MSC_VER
> ;
> #else
> pthread_detach( thread);
> #endif
> }
>
> and called it here:
>
> void ThreadedSocketAcceptor::removeThread( int s ) {
> m_mutex.lock();
> thread_detach(m_threads[s]);
> m_threads.erase( s );
> m_mutex.unlock();
> }
> This fixed the leak.
>
> Gene
>
> __________________________________
> Do you Yahoo!?
> The New Yahoo! Search - Faster. Easier. Bingo.
> http://search.yahoo.com
__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com
|