Re: To thread or not to thread ?
Lourens Veen wrote:
James Kanze wrote:
[...]
the Posix standard
defines a certain number of cancellation points, and the
cancellation will be deferred until the thread to be cancelled
is at one of these points. (Note that all potentially blocking
requests, like read(), recv(), or pthread_cond_wait()---but not
pthread_mutex_wait()!---are cancellation points. There is also
a request pthread_testcancel() which does nothing except create
a cancellation point.)
However, something like that _is_ what I was thinking of. Perhaps with
some more cancellation points thrown in automatically to avoid having
to place explicit ones everywhere. But like I said, I haven't thought
it through, so I have no specific proposals.
I know that some of the members of the committee are discussing
such things, but I'm not up to date on their discussions. In
general, however, there are some differences between
cancellation and exceptions. To be really useful, C++
cancellation more or less has to propagate up to the top; you
don't want to allow catching it, and retrying the operation, for
example. What you'd probably want (just guessing a little) is:
-- the type thrown doesn't have a namable name, so cannot be
caught except with "catch (...)", and
-- exiting the catch block causes it to automatically be
rethrown.
That second point is definitly different from normal exception
semantics.
Another possibility is to do what current Sun CC does: it
unwinds the stack, calling destructors, but does NOT enter catch
blocks. This, too, introduces something new: the RAII idiom has
different semantics than a catch (and in fact, in many cases,
becomes required).
Finally, I don't think it's implementable under Windows. (But I
could easily be wrong there---I don't know Windows very well.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientie objet/
Beratung in objektorientierter Datenverarbeitung
9 place Simard, 78210 St.-Cyr-l'Icole, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]