Bug 88219

Summary: pthread_detach fails if thread has already exited
Product: [Retired] Red Hat Linux Reporter: Benjamin S. Scarlet <scarlet>
Component: glibcAssignee: Jakub Jelinek <jakub>
Status: CLOSED ERRATA QA Contact: Brian Brock <bbrock>
Severity: high Docs Contact:
Priority: medium    
Version: 9CC: fweimer
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2003-04-09 19:21:40 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Benjamin S. Scarlet 2003-04-07 19:46:18 UTC
Description of problem:
The behaviour of pthread_detach has changed from previous versions, and seems
wrong. (Without the posix standard, which I don't have, I can't say for
certain). If the thread being detached has already exited, then pthread_detach
fails with ESRCH, where it used to succeed (and succeeds on Solaris). 

Version-Release number of selected component (if applicable):
glibc-2.3.2-11.9

How reproducible:
Every time.

Steps to Reproduce:
uudecode, gunzip, compile, and run the following code

begin 644 threadtest.c.gz
M'XL("(W3D3X``W1H<F5A9'1E<W0N8P"%4DUOPC`,O?=7>""F!'43VY&._0*T
MVVZ34-2F-%))D..B21/_?4X3"F43Y!`YSQ_OV?'4V++M*@UO>VI0J^JY><^F
M`]A9X^D*8\"X`&4'9RJ8U\Z):"G<2OC)@,\>C:5:3-@)GA32EYW(HG?Y5NN]
M>$FOR\#*67V.0TT=6OCX7*^+[)C8:F5:P1F@$1WF4#KK"<I&(<QW?J"O4UG6
MRH$Y3$)>AWHY\\M9Q3?3Y,`)^:F0)^PMT=\R:=#?AL13T,H"`NU.&=OS<Z]E
MGHA#XX>A\SC'C2+"#8V>Q2A@\$4X%$7MNY:*+`(UB`C`:ES56%;U>`E)>%C!
MXB2AGT`85$SG]O^DG\=\O,%6\DU:#$7#.?'F_Z(]P]C%/SL&PH^.`)F-K7M=
F1%E7#<2U>I6WIE=I4F4CTE/>GU=,N&)*B[D(2_$+01;,?D`#````
`
end

   
Actual results:
$ cc     threadtest.c  -lpthread -o threadtest
$ ./threadtest
foo start
foo done
failure:pthread_detach:3:No such process

Expected results:
$ cc     threadtest.c  -lpthread -o threadtest
$ ./threadtest
foo start
foo done

Additional info:
A cursory look at the code from the nptl in the glibc source RPM suggests that
the tid field in the pthread structure is set to zero when the thread
exits, and pthread_detach doesn't handle that situation. (Joining the thread
after it exits works fine, and pthread_join uses a different test which differs
only by the tid==0 case).

Comment 1 Jakub Jelinek 2003-04-09 19:21:40 UTC
An errata has been issued which should help the problem described in this bug report. 
This report is therefore being closed with a resolution of ERRATA. For more information
on the solution and/or where to find the updated files, please follow the link below. You may reopen 
this bug report if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2003-136.html