[c++-pthreads] cancellation points report failure
Alexander Terekhov
TEREKHOV at de.ibm.com
Sat Dec 20 17:00:49 UTC 2003
Nathan Myers wrote:
[...]
> C library and system calls never throw.
> In the event of cancellation, cancellation point functions report
> failure via their normal means (e.g. return -1, or NULL), and set
> errno if appropriate. Blocked calls fail immediately.
This will essentially break a lot of existing C/C++ code that is
cancel-safe and doesn't known how to handle ECANCELED "error"
(instead of expected behavior -- exception/unwinding).
> In a catch block handling a cancellation exception, functions
> identified as cancellation points work normally.
They work normally because "When a cancellation request is acted
upon, or when a thread calls pthread_exit(), the thread first
disables cancellation by setting its cancelability state to
PTHREAD_CANCEL_DISABLE and its cancelability type to
PTHREAD_CANCEL_DEFERRED. " And, in plain-C POSIX, "The behavior
is undefined if a cancellation cleanup handler or thread-
specific data destructor routine changes the cancelability
state to PTHREAD_CANCEL_ENABLE" (source: TC2).
> When a cancellation exception is swallowed by a catch block,
> subsequently-called cancellation point functions report failure,
> as before, until another cancellation exception is thrown.
That's sticky cancel. Not fun if you're using cancel for canceling
*jobs* and really want to reuse worker threads (your simply catch
and finalize cancel exception, enable cancel again, and continue
with next job).
regards,
alexander.
More information about the c++-pthreads
mailing list