(This is not a new problem, and everyone involved is familiar with it. I was
just surprised not to find a record of it in bugzilla.)
On targets using a recent version of glibc and the NPTL threading package, if
you cancel a thread using pthread_cancel while it is writing to an ostream,
you'll get a fatal error and an abort from glibc. The abort happens because
std::ostream::put uses catch(...), catches the cancellation exception, and does
not rethrow it. You can write a nasty workaround for this, but I'm obviously
not going to recommend it:
int cancelled = 0;
try {
pthread_cleanup_push(something-to-set-cancelled);
write()
pthread_cleanup_pop(discard-cleanups);
} catch (...) {
if (cancelled) throw;
normal-catch-handling;
}
That would only work if there was nothing marked throw() on the way up, of
course.
This problem has been discussed at length on the c++-pthreads list, but I don't
think a consensus was really reached.
--
Summary: libstdc++ and pthread cancellation are incompatible (at
least with NPTL)
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: drow at gcc dot gnu dot org
GCC target triplet: *-*-linux*
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28145