Re: Two pthread libraries on Red Hat 9

"Don Dade" <[email protected]>
Newsgroups gmane.linux.redhat.devel
Message-ID <[email protected]>
Hi Thomas, 

I don't really know what these two libraries are, but I would use some sort 
of sync to make sure that the main thread doesn't exit before the spawned 
one even starts. I do know that LinuxThreads doesn't necessarily immediately 
start the thread spawned by pthread_create(). Maybe the difference in 
behavior is just a race condition due to a subtle timing difference? 

Oh, could the other thread library by NGPT or NPTL? 

Don 

Thomas Bailey writes: 

> Good morning, 
> 
> I've already posted this to the general RedHat list - but it was
> suggested it might be more appropriate to the development list. 
> 
> 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.
> ----------------------------------------------------------------------- 
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.