This patch alters glibc's NPTL (Native POSIX Thread Library) to use c++ exception for thread cancellation.

When HAVE_FORCED_UNWIND is defined, NPTL uses forced unwinding of exception handling mechanism (should we call it ABI exception handling?) to unwind the stack and call clenaup handlers. This allows catching cancellation exception with c++ catch(...) handler.

This patch makes NPTL throw a c++ exception (std::thread_canceled, defined in pthread.h) during thread cancellation. As a result you can use typed handler to identify this situation:

  try
  {

    // ...

  }
  catch (std::thread_canceled const&)
  {
    // ...
    throw;
  }

Note that finalizing std::thread_canceled exception is still illegal.

License

This patch is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; version 2.1 of the License, or (at your option) any later version.

Download

Copyright © 2005 Boris Kolpackov.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, version 1.2; with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts.

Last updated on April 3 2005