[Bug libstdc++/28145] libstdc++ and pthread cancellation are incompatible (at least with NPTL)

mark at codesourcery dot com gcc-bugzilla@gcc.gnu.org
Fri Jun 23 18:26:00 GMT 2006



------- Comment #1 from mark at codesourcery dot com  2006-06-23 18:14 -------
Subject: Re:   New: libstdc++ and pthread cancellation
 are incompatible (at least with NPTL)

drow at gcc dot gnu dot org wrote:

> 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.

> This problem has been discussed at length on the c++-pthreads list, but I don't
> think a consensus was really reached.

I believe that to solve this particular problem, a possible compromise
might be:

(1) Give the thread-cancellation exception a well-known name.
(2) Permit catching that exception -- but only if it is rethrown.

The point of (2) is that it avoids the controversy about whether or not
you are permitted to catch, and then not rethrow, the exception.

Then, you could write:

  try {
    io ();
  } catch (__thread_cancel&) {
    throw;
  } catch (...) {
    /* Normal catch handling.  */
  }

That would provide a mechanism for making libstdc++ (and other
applications) cancel-safe.  It would still not solve the general
philosophical issues about whether or not you should be allowed to fail
to "eat" the cancellation exception, but I think it would be a step forward.

Another way to do this, instead of having a named exception, would be to
have a "__uncaught_cancellation()" function, similar to
"std::__uncaught_exception()".  Then, you would do:

  try {
    io ();
  } catch (...) }
    if (__uncaught_cancellation ())
      throw;
    /* Normal catch handling.  */
  }


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28145



More information about the Gcc-bugs mailing list