[c++-pthreads] Re: What are the real issues?
Fergus Henderson
fjh at cs.mu.OZ.AU
Wed Jan 7 03:57:04 UTC 2004
On 06-Jan-2004, Howard Hinnant <hinnant at twcny.rr.com> wrote:
> In the scenario I've outlined, code written by different parties would
> work together in a thread/cancel environment as long as:
>
> 1. The code met basic exception safety requirements.
> 2. The code was not compute-bound (and thus ignored cancellation
> requests).
It would also require
3. The code doesn't block for I/O.
wouldn't it?
> For example, I could've sprinkled my helloworld with std::lib calls,
> and it still would've been ok because the std::lib maintains basic
> exception safety.
Won't it fail to cancel the threads if the output blocks, e.g. because
it is redirected to Unix pipe that fills up?
> Admittedly if a std::lib call took an inordinate
> amount of time, cancellation requests would be ignored during that
> call. But it seems we already have the risk of ignoring cancellation
> requests anyway.
That risk of cancellations being ignored can be avoided by ensuring
that all the code that you call is strongly cancellation-safe.
The problem with your suggested approach is that unless the cancellation
framework is part of the standard library, in general it's not possible
for third parties to write strongly cancellation-safe code!
Writing strongly cancellation-safe code requires (a) being able to poll
for cancellation and (b) being able to do blocking I/O in a way that
will wake up when a cancellation request is received.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
More information about the c++-pthreads
mailing list