pthread_cancel and EH: let's try this again
Alexander Terekhov
terekhov at web.de
Wed Jul 27 14:57:17 UTC 2005
Peter Dimov wrote:
[...]
> Before that, an implementation that used a separate "cleanup mode" flag
> (which has the advantage of not interfering with the client's cancelstate
> calls) was conforming.
Nope. Because
http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_09.html#tag_02_09_05_01
says nothing about "separate cleanup mode flag" and hence per XSH 2.9.5,
http://opengroup.org/austin/mailarchives/austin-review-l/msg01450.html
can be written as
....
int state;
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &state);
if (PTHREAD_CANCEL_ENABLE == state) {
pthread_setcancelstate(state, &state);
pthread_cancel(pthread_self());
pthread_testcancel();
errno = ECANCELED;
perror("NON-CONFORMING IMPLEMENTATION");
abort();
}
....
that's apart from
....
int state;
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &state);
if (PTHREAD_CANCEL_ENABLE == state) {
pthread_setcancelstate(state, &state); // Uh...
//pthread_cancel(pthread_self());
//pthread_testcancel();
pthread_exit(PTHREAD_CANCELED);
}
....
Of course, the "real" fix would be introduction of int
pthread_expectedcancel() incapsulating
expected_exception<thread_cancel_request>() query and cancel state check.
....
if (pthread_expectedcancel()) {
pthread_cancel(pthread_self());
pthread_testcancel();
errno = ECANCELED;
perror("IMPLEMNATION BUG");
abort();
}
....
....
if (pthread_expectedcancel()) {
pthread_exit(PTHREAD_CANCELED);
}
....
but without (2-phase) EH machinery, POSIX just can't do that.
regards,
alexander.
More information about the c++-pthreads
mailing list