Hi All, Please show me how stupid I am :-) There does not appear to be a way to avoid resource leaks in a library that must manage thread-local storage.
The problem appears to be that the destructor given to pthread_key_create is not called for the `main thread' (uncertain terminology). Example: library private freekey() free resources, like fds deallocate thread-local storage public foo() pthread_once -> initialize pthread_key pthread_getspecific -> fetch thread-local storage if there wasn't any already allocated, allocate thread-local storage maybe initialize some stuff, like fds do your thing pthread_setspecific -> update thread-local storage main 1. call foo() 2. create thread that calls foo() 3. pthread_join() Both invocations of foo() will work correctly: they will each have their own thread-local storage allocated. When the thread created at (2) exits, freekey() will be called. But, when the process exits, freekey() will NOT have been called for the invocation of foo at (1) (what I am calling the `main thread'). I'm pretty certain I'm using pthread_(set|get)specific in the spirit intended. Am I misunderstanding something, or is this a flaw in our implementation? (BTW, this holds for -CURRENT and -STABLE.) Cheers, -- Jacques A. Vidrine <[EMAIL PROTECTED]> http://www.celabo.org/ NTT/Verio SME . FreeBSD UNIX . Heimdal Kerberos [EMAIL PROTECTED] . [EMAIL PROTECTED] . [EMAIL PROTECTED] To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message