Bug 629673

Summary: libpthread: thread-specific data destructor is never invoked
Product: [Fedora] Fedora Reporter: Bart Van Assche <bart.vanassche+redhat>
Component: glibcAssignee: Andreas Schwab <schwab>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: low    
Version: 13CC: cquike, denis.arnaud_fedora, fweimer, jakub, schwab
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2010-09-29 12:34:42 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:
Attachments:
Description Flags
Test program. none

Description Bart Van Assche 2010-09-02 16:59:05 UTC
Created attachment 442676 [details]
Test program.

Description of problem:
The POSIX threads function pthread_key_create() allows to specify a destructor function as the second argument. Apparently that destructor function is never invoked.


Version-Release number of selected component (if applicable):
$ head -n 1 /etc/issue.net 
Fedora release 13 (Goddard)
$ rpm -qf /lib64/libpthread.so.0
glibc-2.12-3.x86_64


How reproducible:
100%


Steps to Reproduce:
1. Build pthread_once.cpp
2. Run ./pthread_once

  
Actual results:
key = 0x0x1313010
Done.


Expected results:
key = 0x0x1313010
destructor(): arg = 0x0x1313010
Done.

Comment 1 Bart Van Assche 2010-09-02 18:16:13 UTC
Notes:
- I have not yet found any clause in IEEE Std 1003.1 that specifies whether or not thread-local destructors must be invoked when the main thread exits.
- I have not yet been able to find any clause in the same document that specifies whether or not it is allowed to call pthread_exit() from main().
See also http://www.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_09.

Comment 2 Denis Arnaud 2010-09-02 18:31:07 UTC
I've tested your (attached) program on Debian (Squeeze/Sid), and the result is the same as on Fedora.

Comment 3 Bart Van Assche 2010-09-02 18:38:26 UTC
(In reply to comment #2)
> I've tested your (attached) program on Debian (Squeeze/Sid), and the result is
> the same as on Fedora.

I assume that's because Debian and Fedora compile glibc from the same source code. It would be great if someone could find out what the POSIX spec says about what the behavior really should be.

Comment 4 Andreas Schwab 2010-09-29 12:34:42 UTC
<http://opengroup.org/onlinepubs/9699919799/functions/_Exit.html#tag_16_01_03_01>:

Threads terminated by a call to _Exit() or _exit() shall not invoke their cancellation cleanup handlers or per-thread data destructors.