Boost logo

Boost :

Subject: Re: [boost] threads: how to remotely kill a thread?
From: David M. Cotter (me_at_[hidden])
Date: 2009-10-10 12:58:33


yes i have seen the error of my ways, and am now using thread.interrupt
() and i sprinkle interruption_point() in my inner loops of the thread

thanks for the feedback.

-dave

On Oct 9, 2009, at 9:20 PM, Yigong Liu wrote:

> It is kind of dangerous for one thread to kill another thread
> forcefully or directly, since the 2nd thread may be in the middle of
> holding a system resource or changing some state. Killing it may
> left the system in corrupted state. better using "cooperative"
> shutdown, the 1st thread sends the 2nd thread some notification,
> either thru shared state or interrupt. For similar reasons, java
> deprecated many thread api (http://java.sun.com/j2se/1.4.2/docs/guide/misc/threadPrimitiveDeprecation.html
> ).
>
> On Fri, Oct 2, 2009 at 9:16 AM, Andrey Semashev <andrey.semashev_at_[hidden]
> > wrote:
> David M. Cotter wrote:
> say i'm on the main thread, and i've got a thread::id of some other
> preemptive thread. i do not have the actual boost::thread object
> any more.
>
> and i want to unceremoniously kill that thread. like right now.
>
> how do i kill it? i don't see a way to recover the actual
> boost::thread from the thread::id. but even if i could, and then
> call thread.interrupt(), that's more of a polite request which is
> free to be ignored, rather than a you_must_die_now() thing.
>
> The main problem with killing threads is that it doesn't unwind the
> stack and thus breaks RAII. Therefore the best "official" way to
> terminate the thread in C++ is to interrupt it. If you want to do it
> the hard way, you're in C world with pthread_kill and alikes.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk