Red Hat Bugzilla – Full Text Bug Listing
|Summary:||pthread_exit() does not terminate thread when called from termination handler|
|Product:||Red Hat Enterprise Linux 3||Reporter:||Yadnesh Phadke <yphadke>|
|Component:||glibc||Assignee:||Jakub Jelinek <jakub>|
|Status:||CLOSED NOTABUG||QA Contact:|
|Fixed In Version:||Doc Type:||Bug Fix|
|Doc Text:||Story Points:||---|
|Last Closed:||2004-09-27 20:41:50 EDT||Type:||---|
|oVirt Team:||---||RHEL 7.3 requirements from Atomic Host:|
Description Yadnesh Phadke 2004-09-15 08:32:20 EDT
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): glibc-devel-2.3.2-95.3 glibc-common-2.3.2-95.3 glibc-utils-2.3.2-95.3 glibc-headers-2.3.2-95.3 glibc-2.3.2-95.3 glibc-profile-2.3.2-95.3 glibc-kernheaders-2.4-8.34 How reproducible: Always reproducible. See attached test program Steps to Reproduce: 1. create a thread and set termination handler using std::set_terminate() 2. the termination handler should call pthread_exit(0) 3. explicitly throw from the thread function so that the termination handler is invoked. Actual results: The thread loops infinitely until the main thread calls exit(0). Expected results: thread calling pthread_exit() should exit, eventhough other threads in the process continue normally Additional info: Question: Is there anything incorrect in the test program?
Comment 1 Yadnesh Phadke 2004-09-15 08:35:40 EDT
Created attachment 103860 [details] sample to reproduce problem compile using g++ -lpthread pthread3.cpp
Comment 2 Suzanne Hillman 2004-09-15 14:54:52 EDT
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.
Comment 3 Yadnesh Phadke 2004-09-16 00:37:36 EDT
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.
Comment 4 Jakub Jelinek 2004-09-16 03:57:17 EDT
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.
Comment 5 Yadnesh Phadke 2004-09-16 04:58:43 EDT
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 execution. 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?
Comment 6 Ulrich Drepper 2004-09-27 20:41:50 EDT
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 want. Period. 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.