bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: possible bug sighting - exit hang


From: Wolfram Gloger
Subject: Re: possible bug sighting - exit hang
Date: Mon, 19 Nov 2001 16:40:34 +0100 ("MET)

Hello,

> While investigating a JDK bug, I noticed a problem in
> glibc/linuxthreads.

Having reread pthreads documentation, I think you're right, this is a
problem with asynchronous thread termination in LinuxThreads in the
special case of 'falling off the end of main()', _however_...

> Basically, a process may hang on exit if a thread is doing memory
> allocation
> at the same time. Here is the test code:
> 
> --------------------------------------------------------
> #include <stdio.h>
> #include <pthread.h>
> 
> void * start_routine(void * arg)
> {
>   printf("child thread pid=%d\n", getpid());
>   while(1) malloc(100);
>   return NULL;
> }
> 
> int main(void)
> {
>   pthread_t tid;
>   printf("main thread pid=%d\n", getpid());
>   pthread_create(&tid, NULL, start_routine, NULL);
>   return 0;
> }

... if this is really the stripped-down version of the Java code I'd
suggest that you consider either creating the thread detached or
joining with it.  Falling off the end of main lets all threads that
are still running just 'evaporate' at some unspecified time with
absolutely no control over their resources.

I believe this is _very_ rarely what you want.

> The problemetic code is in pthread.c, pthread_onexit_process
> (glibc-2.2.4):
...
> Line 796 needs to grab malloc lock and it may hang if one of the threads 
> is killed when it's still holding the lock. The test code works fine
> with
> line 796 commented out. I don't see why you need to free the manager
> thread
> stack, the process is gone, there is no memory leak to worry about.

I disagree, this should be fixed in another way.  There are other
locks such as file locks that are potentially affected in this rare
case.  I think we should perform the equivalent of
pthread_atfork_prepare() in the main thread when falling of the end of
main().  Then all present and future libc locks would be kept and the
remaining threads could be terminated safely.  I'll prepare a patch if
no-one else beats me to it.

Regards,
Wolfram.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]