[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
possible bug sighting - exit hang
From: |
Hui Huang |
Subject: |
possible bug sighting - exit hang |
Date: |
Thu, 15 Nov 2001 11:20:11 -0800 |
Greetings!
While investigating a JDK bug, I noticed a problem in
glibc/linuxthreads.
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;
}
--------------------------------------------------------
The problemetic code is in pthread.c, pthread_onexit_process
(glibc-2.2.4):
793 if (self == __pthread_main_thread)
794 {
795 waitpid(__pthread_manager_thread.p_pid, NULL, __WCLONE);
796 free (__pthread_manager_thread_bos);
797 __pthread_manager_thread_bos = __pthread_manager_thread_tos =
NULL;
798 }
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.
regards,
-hui
- possible bug sighting - exit hang,
Hui Huang <=