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.
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.
I've tested your (attached) program on Debian (Squeeze/Sid), and the result is the same as on Fedora.
(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.
<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.