Hi Matt,
interrupt() doesn't lead to any resource leaks or missed cleanup. If you
look closer into documentation you'll see that interrupt() throws a
boost::thread_interrupted exception from well-defined cancellation points
which is caught in boost::thread's thread-main function. As with any other
exception stack will be unwound automatically and thread gracefully
finished.
If you write your program in exception-safe manner nothing leaks.
The problems may arise if you're unaware of these cancellation points.
Imagine you call join() from object destructor while one itself might be
executing in boost:thread. If someone interrupts this thread, you'll get
exception thrown from destructor which results in undefined behavior.
In other regards I'd like to see io_service::run as a cancellation point.
Best wishes,
Yuri
On Sat, May 19, 2012 at 9:04 AM, Gruenke, Matt <***@tycoint.com> wrote:
> **
>
> Define cleanup. If you mean that you want to try and flush some buffers
> or something before calling exit(), then I can imagine cases where
> thread::interrupt() might be helpful. However, if you mean to shutdown in
> such a way that would satisfy memory leak checking tools, then you're
> likely to find that thread::interrupt() leads only down a road of dashed
> hopes, sorrows, and despair.
>
> I think what Dale means is that because there are blocking calls which
> thread::interrupt() doesn't cancel, you can have a situation where thread A
> tears down resources used by thread B, which thread B later tries to use.
> This can result in a shutdown which nobody would consider "clean" (i.e.
> segfault, assertion failure, etc.).
>
> Sorry, but in a non- garbage-collected language, there are no easy
> answers, nor substitutes for sorting out object ownership & shutdown
> sequences.
>
>
> Matt
>
>
>
> -----Original Message-----
> From: kir
> Sent: Thu 5/17/2012 11:51 AM
> To: asio-***@lists.sourceforge.net
> Subject: Re: [asio-users] thread::interrupt and asio::ios_service::run
>
> On Thu, May 17, 2012 at 5:46 PM, Dale Wilson wrote:
> > The only safe thing to do after cancelling a thread is to kill the entire
> > process.
>
> which btw is my goal, i use interrupt for controlled cleanup and quit
>
> > cancelling a
> > thread inherently leaves any resources that thread was using in an
> unstable
> > state.
>
> That is wrong. There are defined cancelation points. If thread avoids
> them there is no chance it will be cancelled. Also
> boost::thread::interrupt results in exception, not cancellation in
> sense of pthread_cancel.
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> asio-users mailing list
> asio-***@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/asio-users
> _______________________________________________
> Using Asio? List your project at
> http://think-async.com/Asio/WhoIsUsingAsio
>
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> asio-users mailing list
> asio-***@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/asio-users
> _______________________________________________
> Using Asio? List your project at
> http://think-async.com/Asio/WhoIsUsingAsio
>
>