This is the mail archive of the libc-alpha@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: New LinuxThreads bug, I think


On Wed, 26 Apr 2000, Kaz Kylheku wrote:

> Date: Wed, 26 Apr 2000 22:15:53 -0700 (PDT)
> From: Kaz Kylheku <kaz@ashi.footprints.net>
> To: libc-alpha Mailinglist <libc-alpha@sourceware.cygnus.com>
> Subject: New LinuxThreads bug, I think
> 
> The Single UNIX Spec says that when all threads call pthread_exit()
> the process terminates as if it called exit(0).
> This means that atexit functions are called, and stdio buffers are flushed.
> 
> LinuxThreads does not do this.  For example, the unflushed stdout output of a
> test program whose threads call pthread_exit() is simply discarded!

Okay, it's fixed. The solution was not quite as obvious as I thought it might be.

The trick is not to have the thread manager voluntarily terminate itself with
_exit(0) when the main thread terminates. Instead, when the main thread
terminates, the thread manager just continues its main loop.

Now, the main thread is made to terminate via exit(0) instead of _exit(0). The
call to exit(0) will call back into LinuxThreads via a registered __on_exit
handler. This handler, pthread_exit_process, sends the thread manager a
REQ_PROCESS_EXIT, waits for the reply and everything is cool.

The naive fix of just having the main thread call exit(0) inside pthread_exit()
did not work because pthread_exit_process will suspend indefinitely waiting
for a reply from the pthread manager which has already quit.

Patch @ 11. ;)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]