threads: how to remotely kill a thread?

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.

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()
FWIW, there's already a discussion about it there http://lists.boost.org/boost-users/2007/06/28603.php Apparently it goes from "you can't" to "implement it yourself by using a shared object between your threads, which tells the other one to quit.". Philippe

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.
participants (3)
-
Andrey Semashev
-
David M. Cotter
-
Philippe Vaucher