This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: problem with pthread and waitpid()
- To: Britton <fsblk at aurora dot uaf dot edu>
- Subject: Re: problem with pthread and waitpid()
- From: Kaz Kylheku <kaz at ashi dot footprints dot net>
- Date: Sat, 16 Sep 2000 23:26:33 -0700 (PDT)
- cc: libc-alpha at sources dot redhat dot com
On Sat, 16 Sep 2000, Britton wrote:
> Date: Sat, 16 Sep 2000 21:37:25 -0800 (AKDT)
> From: Britton <fsblk@aurora.uaf.edu>
> To: libc-alpha@sources.redhat.com
> Subject: problem with pthread and waitpid()
>
>
> I have noticed a problem with the LinuxThreads implementation. When a
> process forks and execs a program that spawns threads, then waitpids on
> that child, the wait ends when the initial thread of the exec'd program
> finishes, but before the spawned threads are necesarilly dead.
Which version of LinuxThreads and how are the threads terminating?
When the initial thread terminates by calling pthread_exit() or exit(), it
synchronizes with the thread manager, waiting until it cleans out other
threads.
The exit() case (also, returning from main()) is trapped using a registered
callback within LinuxThreads which sends the process-wide-exit request to the
thread manager and waits for the reply.
Of course, the whole thing can break down if something is wrong with the child
process. For example if the main thread crashes or calls _exit() rather than
exit(), then the parent process will be notified before the multithreaded child
has fully cleaned up the crash. It can take up to two seconds for the thread
manager to even notice that its parent is now the init daemon and blow
everything away.
I addressed a couple of bugs related to LinuxThreads shutdown since 2.1.3. The
two that I recall off the top of my head are:
- a potential unnecessary two second delay in shutdown due to the 2000
millisecond poll() timeout in the thread manager's loop.
- failure to perform atexit() processing and flush stdio streams in the
case that all threads call pthread_exit().
View the linuxthreads/ChangeLog using cvsweb.