[cpp-threads] Asynchronous Execution Issues

Boehm, Hans hans.boehm at hp.com
Sat Apr 25 01:03:41 BST 2009


> From:  Lawrence Crowl
> 
> On 4/24/09, Oliver Kowalke <oliver.kowalke at gmx.de> wrote:
> > I'm currently implementing a library (boost.task formaly known as 
> > boost.threadpool) which implements this kind of functionality.
> 
> Thanks for the heads up.
> 
> >  - second item:
> >  launch_in_thread() (== std::caching_async()) returns a  
> handle object 
> > which contain a smart pointer of boost::thread  (==std::thread). If 
> > the last instance of this handle gets out of  scope the custom 
> > destructor of smart pointer calls thread::join()  on the 
> thread object 
> > (releasing the thread).
> 
> And what happens to objects of thread storage duration?
> 
Annoyingly, I think neither of the obvious answers is workable.  If you don't invoke destructors, this is very likely to leak.  If you do invoke destructors, destruction ends up executing completely unpredictable code (potentially associated with earlier tasks), which may end up acquiring completely unpredictable locks as a result of the destructor invocation, either foiling all attempts at lock ordering (and hence standard deadlock prevention), or rendering a routine that uses this unsafe to use while holding a lock.

Again, this strikes me as a fundamental design flaw, not something specific to the async API.

I'm starting to have second thoughts about non-trivial destructors for thread_locals ...

Hans


More information about the cpp-threads mailing list