Good morning, I was wondering if anyone could explain to me the difference between the pthread libraries in /lib and /lib/tls on RedHat 9. I ask because the library in /lib/tls (which is linked by default when you supply -lpthread to gcc) displays unexpected behavior, whereas the library in /lib or /lib/i686, behaves correctly.
The code below demonstrates the difference: #include <dlfcn.h> #include <stdio.h> #include <stdlib.h> #include <netdb.h> #include <time.h> #include <pthread.h> #include <unistd.h> #ifdef __cplusplus extern "C" { #endif /// Our global key for accesing the TSS static pthread_key_t gcKey; /// Destructor static void DestroyKey (void* pcValue) { printf("Freeing TSS\n"); abort(); free (pcValue); } /// Initialization code static void* Init(void *arg) { pthread_key_create (&gcKey, DestroyKey); pthread_setspecific(gcKey, malloc(42)); return (void *) 0; } int main (int argc, char* argv[]) { pthread_t myThread; pthread_create(&myThread, NULL, Init, NULL); return 0; } } In this example program, we create a thread, and allocate some thread specific storage, passing a pointer to the DestroyKey function to pthread_key_create. We would expect this function to be called when the thread's thread specific storage is destroyed, i.e. on thread exit. We would then expect the program to print a message and abort (i.e. dump core). When linked against /lib/tls/libpthread-0.29.so, DestroyKey is not called. If I change the permissions on /lib/tls/libpthread-0.29.so and /lib/tls/libc-2.3.2.so to make them unreadable, so my program gets linked against /lib/i686/libpthread.so.0 and /lib/i686/libc.so.6, DestroyKey is called on thread exit. I'm curious as to whether anyone knows a) if this is a bug in the default threading library and b) if anyone knows a more elegant way to force my application to link against the 'right' libraries other than changing the permissions on the 'wrong' libraries. I have tried the -nostdlib option to gcc. Regards Tom Bailey ----------------------------------------------------------------------- The information contained in this e-mail is confidential and solely for the intended addressee(s). Unauthorised reproduction, disclosure, modification, and/or distribution of this email may be unlawful. If you have received this email in error, please notify the sender immediately and delete it from your system. The views expressed in this message do not necessarily reflect those of LIFFE Holdings Plc or any of its subsidiary companies. ----------------------------------------------------------------------- -- redhat-list mailing list unsubscribe mailto:[EMAIL PROTECTED] https://www.redhat.com/mailman/listinfo/redhat-list