pthread_cancel and EH: let's try this again
Alexander Terekhov
terekhov at web.de
Wed Jul 13 18:11:10 UTC 2005
Jason Merrill wrote:
>
> On Wed, 13 Jul 2005 17:28:50 +0200, Alexander Terekhov <terekhov at web.de> wrote:
>
> > Jason Merrill wrote:
> > [...]
> >> while (true)
> >> try
> >> {
> >> body();
> >> }
> >> catch (...)
> >> {
> >> recover();
> >> }
> >>
> >> Under the old non-EH implementation this thread cancelled properly.
> >
> > You mean with omitted recovery? That's hardly "properly".
> >
> > Cancel-unaware code is not meant to be canceled.
> >
> > It's as simply as that.
>
> A customer of ours has code along those lines in a package that uses
> pthread_cleanup_push/pop to handle cleanups on cancellation. It works fine
> under Solaris, tru64, and older linux systems.
^^^^^
Uhmm, regarding Compaq Tru64 UNIX V5.1B (Rev. 2650)...
>
> It IS cancel-aware. The problem is that allowing catch(...) to catch
> cancellation changes what it MEANS to be cancel-aware in an incompatible
> way.
spe147.testdrive.hp.com> cxx -pthread -o jason jason.cpp
spe147.testdrive.hp.com> ./jason
Throwing cancel exception...
C++ catch...
Throwing cancel exception...
PTHREAD_CATCH_NP(pthread_cancel_e)...
Exception: Thread has been canceled (dce / thd)
pthread_cancel_e has been raised and swallowed twice, Jason.
spe147.testdrive.hp.com> cat jason.cpp
#include <stdio.h>
#include <pthread.h>
#include <pthread_exception.h>
extern "C" void tru64_native_pthread_exception_handling() {
pthread_cancel(pthread_self());
PTHREAD_TRY_NP {
printf("Throwing cancel exception...\n");
pthread_testcancel();
}
PTHREAD_CATCH_NP(pthread_cancel_e) {
printf("PTHREAD_CATCH_NP(pthread_cancel_e)...\n");
pthread_exc_report_np(PTHREAD_THIS_CATCH_NP);
}
PTHREAD_ENDTRY_NP
}
int main() {
pthread_cancel(pthread_self());
try {
printf("Throwing cancel exception...\n");
pthread_testcancel();
}
catch(...) {
int state;
printf("C++ catch...\n");
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &state);
tru64_native_pthread_exception_handling();
}
printf("pthread_cancel_e has been raised and swallowed twice, Jason.\n");
}
spe147.testdrive.hp.com>
regards,
alexander.
More information about the c++-pthreads
mailing list