Bug 132638 - pthread_exit() does not terminate thread when called from termination handler
Summary: pthread_exit() does not terminate thread when called from termination handler
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: glibc   
(Show other bugs)
Version: 3.0
Hardware: i686 Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2004-09-15 12:32 UTC by Yadnesh Phadke
Modified: 2007-11-30 22:07 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-09-28 00:41:50 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
sample to reproduce problem (1.46 KB, text/plain)
2004-09-15 12:35 UTC, Yadnesh Phadke
no flags Details

Description Yadnesh Phadke 2004-09-15 12:32:20 UTC
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 12:35:40 UTC
Created attachment 103860 [details]
sample to reproduce problem

compile using
g++ -lpthread pthread3.cpp

Comment 2 Suzanne Hillman 2004-09-15 18:54:52 UTC
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 04:37:36 UTC
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 07:57:17 UTC
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 08:58:43 UTC
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-28 00:41:50 UTC
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.


Note You need to log in before you can comment on or make changes to this bug.