[c++-pthreads] Re: pthread_cancel and EH: let's try this again
Wil Evers
wil at bogo.xs4all.nl
Tue Jul 19 21:08:48 UTC 2005
Peter Dimov wrote:
> The natural way to signal cancellation is with an exception, not an
> error code and a multitude of ifs. The exception model has obviously
> been considered superior by the Posix folks, so superior that they even
> defined their own EH mechanism in the C binding.
I disagree. IMO, a cancellation request is just another external event
(usually) triggered by something outside of the current thread - much
like data arriving on a socket, or the signalling of a condition
variable. As we all know, such events are best dealt with when the
target thread is ready for them.
As the discussion on this list illustrates, mapping cancellation
requests to exceptions is causing real headaches. This is because
cancellation requests are piggybacked onto system calls originally
designed for other purposes.
In addition, and contrary to common usage of exceptions, a cancellation
request is *not* an error in the sense that it immediately prevents the
current thread from progressing any further. A cancellation request is
simply one of the things a thread is supposed to (eventually) handle -
if the application's design demands so.
That said, I realize it is far too late to change the decisions made by
the POSIX folks. All we can do is try to find ways to handle
cancellation exceptions gracefully.
- Wil
More information about the c++-pthreads
mailing list