Boost logo

Boost :

From: Matthew Austern (austern_at_[hidden])
Date: 2002-01-14 14:41:10


Jens Maurer wrote:
>
> Lee Brown wrote:
> > I do have one question: why doesn't Boost.threads seem to support
> > thread cancelation? It doesn't seem to be mentioned in the documentation.
>
> Thread cancelation is difficult to do correctly in a C++ program,
> because you want to run all the destructors of stack objects of
> the thread being canceled.

It's not obvious that that's what you want. Remember,
thread cancelation is not a graceful request; it's the moral
equivalent of Unix's "kill", maybe even "kill -9". One valid
interpretation is that it ought to mean that the thread should
cease processing immediately, instead of continuing to do more
stuff like stack unwinding.

This is definitely unsafe, but then, stack unwinding from an
asynchronous exception isn't exactly safe either. In either
cases, about the best you can say is that if you know the
rules, and you're careful, it's possible to write an
application that works correctly under those rules.

The question is whether it's a good idea to provide a feature
that (a) is rarely needed; (b) is unsafe if used carelessly;
and (c) can be used safely if you're extremely careful.

(And I hope it doesn't sound like I've biased that question
toward a "no" answer, because I actually think the answer
should usually be "yes". There's a difference between a
feature that's rarely needed and one that's never needed.)

                        --Matt


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