[c++-pthreads] pthread_cancel and EH: let's try this again
Peter Dimov
pdimov at mmltd.net
Mon Jul 18 17:17:29 UTC 2005
Ted Baker wrote:
> On Mon, Jul 18, 2005 at 06:53:23PM +0300, Peter Dimov wrote:
>>> Yes, because it is unsafe, and C++ wants to be safer than C.
>>
>> I'm not sure I follow. In what way is a cancellation exception less
>> safe than any other exception?
>
> In this context, I was thinking of the problem of not knowing when
> and where such an exception might be thrown. As others have
> pointed out, when you are calling a library function written
> in C (whether part of the standard C library or some other library)
> you don't know whether it will call something that qualifies as
> a thread cancellation point. This is a problem with C, already,
> and wrapping it in C++ does not make the problem go away.
In other words, the answer is a qualified "none".
When you are calling a function written in C++ you don't know whether it
will throw unless this is documented.
It is true that so far we've been able to assume that a function written in
C doesn't throw when thread cancellation is not in use. But we'll still be
able to assume that.
> I was also thinking of some of the baroque semantic proposals I've
> seen on this e-mail thread, ...
Well, if a cancellation exception is given semantics that make it different
from any other exception, it can be less safe, I agree. If it isn't, it
won't.
> 2) Are exceptions safe, in general?
We've spent the last decade in learning how to use them safely. It doesn't
make sense to discard this knowledge.
When 'new' was changed to throw this broke millions of lines of code, and
C++ survived the transition. The introduction of cancellation points - even
into the C part of the standard library - is almost a non-event compared to
that.
More information about the c++-pthreads
mailing list