|
Threads-Devel : |
Subject: Re: [Threads-devel] Leak on not joined thread / Linux / Boost 1.34.1
From: Emilio Pombo (epombo_at_[hidden])
Date: 2009-02-16 10:22:39
Thanks Anthony! Finally we continue with boost::thread, detaching
object -keeping reference alive- when no join was done, and works well for
now!
I think we are moving for a newer boot version in a few days! I've redden
new features specially on threads and are greats, thanks again you and all
of the boost guys for this awesome libraries!
Regards,
e-milio.
----- Original Message -----
From: "Anthony Williams" <anthony_at_[hidden]>
To: <threads-devel_at_[hidden]>
Sent: Monday, February 16, 2009 5:19 PM
Subject: Re: [Threads-devel] Leak on not joined thread / Linux / Boost
1.34.1
> At Mon 16 Feb 2009 12:59:38 UTC, Emilio Pombo <epombo_at_[hidden]>
> wrote:
>
>> After some code comments -the old style leak find method school ;)- the
>> result was really surprising for me... the leaks were produced after
>> each thread launch, so at this point I quickly change Boost::Thread by
>> POSIX Thread -the default option basically on Asterisk development-,
>> the problem was still there. After that I released that on some flows
>> of execution the module wasn't leaking, and that flows matched with
>> ones were I have to join the thread (on some cases my requirements
>> force me to avoid join and terminate thread directly from launching
>> function with no join from another thread).
>
> You have to explicitly join or detach every thread to ensure that the
> thread management data is correctly cleaned up.
>
>> Finally solved the problem with POSIX Thread, creating always
>> detachable threads -non joinable-, and doing sync with a semaphore. I
>> think that the problem on boost::thread was significantly the same as
>> with POSIX, but you can't access this kind of details on boost::thread,
>> or at least I think you must be "protected" by surround implementation
>> from a leak if you start a thread that you never execute method
>> ::join() from another thread -I searched on boost doc, I founded a
>> ::detach() method, but on my version of boost at least wasn't available,
>> may be executing this on non joinable flows could be the solution-...
>> any comments?
>
> In boost 1.35 or later there is a boost::thread::detach function. In
> boost 1.34, the thread is detached when you destroy the boost::thread
> object. So, only keep around the boost::thread object if you intend to
> join with the thread; otherwise just make the boost::thread object
> temporary:
>
> void launch_thread()
> {
> boost::thread t(some_func);
> } // t is destroyed here; thread is detached.
>
> You could avoid giving the thread variable a name at all:
>
> boost::thread(some_func); // temporary destroyed at end of statement =>
> detached thread
>
> Anthony
> --
> Anthony Williams
> Author of C++ Concurrency in Action | http://www.manning.com/williams
> just::thread C++0x thread library | http://www.stdthread.co.uk
> Custom Software Development |
> http://www.justsoftwaresolutions.co.uk
> Just Software Solutions Ltd, Registered in England, Company Number
> 5478976.
> Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK
>
>
> _______________________________________________
> threads-devel mailing list
> threads-devel_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/threads-devel
>
> __________ Información de NOD32, revisión 3846 (20090211) __________
>
> Este mensaje ha sido analizado con NOD32 antivirus system
> http://www.nod32.com
>
>