Description of problem:
I have set a termination handler for unhandled exceptions that may
occur in a thread. But, it seems that after the termination handler
calls pthread_exit(), the termination handler is automatically
called, ... this keeps on repeating until the process exits.
Version-Release number of selected component (if applicable):
How reproducible: Always reproducible.
See attached test program
Steps to Reproduce:
1. create a thread and set termination handler using
2. the termination handler should call pthread_exit(0)
3. explicitly throw from the thread function so that the termination
handler is invoked.
The thread loops infinitely until the main thread calls exit(0).
thread calling pthread_exit() should exit, eventhough other threads
in the process continue normally
Is there anything incorrect in the test program?
Created attachment 103860 [details]
sample to reproduce problem
g++ -lpthread pthread3.cpp
If you're looking to check if you're doing something wrong, you'll
want to be talking to support. If you have an up-to-date entitlement,
go to http://www.redhat.com/support, or call 800-REHDAT1
Bugzilla can take a very long time to get a reply from the developers,
as this is a bug tracking system, and not a form of support.
I am not looking to check where I have gone wrong.
There is a bug in pthread_exit() that causes a infinite loop when
called from termination handler, as I have already explained.
That is not a bug, that is a feature.
In the termination handler you are supposed to do just cleanups
you want to do and exit the process, not the thread only.
The whole application is not in a state where it can run any further.
As per my knowledge, the purpose of having a thread termination
handler and pthread_exit() is to stop a thread (and not process),
irrespective of whether the thread had a error or did a successful
One of the advantages of having multiple threads is that a process
need not terminate for a problem in thread.
Consider an example of a big 24/7 application that creates threads
for each user request (or consider a multithreaded server).
Logically, the application should not terminate, if there is
unhandled exception for one of the user requests (only the thread
handling the request should cleanup and terminate). The application
process should continue to serve other user requests.
Most of the operating systems that I know do not terminate the
processes on calling pthread_exit() from termination handler.
I do not think that this is a feature. Can you please guide me to
the documentation of this feature?
It is irrelevant what you think the behavior should be. Exception
termination handling is defined as is for RHEL3. There is no
specification anyway which demands that the code allows to do what you
If you want to change that, develop appropriate code and get it
integrated in the upstream projects (gcc and/or glibc). Or pay
somebody to do the work for you. If you manage to do this, we'll
automatically have the new code in the next version of RHEL.