public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Bruce Korb <bkorb@pacbell.net>
To: linux-kernel@vger.kernel.org, bug-glibc@gnu.org, guile-user@gnu.org
Cc: bkorb@pacbell.net
Subject: How do you clean up with pthread locks held?
Date: Sat, 20 Oct 2001 04:52:23 -0700	[thread overview]
Message-ID: <3BD16577.5093D070@pacbell.net> (raw)


I should note that I do not conciously use pthreads.
Every thread in this process group is a complete
new process.  But the Guile library may.  Don't know.

Here's the stack trace (linux 2.4.7 & glibc-2.1):

> 4008cc66 sigsuspend () from /lib/libc.so.6
> 400324d0 __pthread_wait_for_restart_signal () \
>           from /lib/libpthread.so.0
> 40034355 __pthread_alt_lock () from /lib/libpthread.so.0
> 40030bb2 pthread_mutex_lock () from /lib/libpthread.so.0
> 400d223b free () from /lib/libc.so.6
> 400c4c91 fclose@@GLIBC_2.1 () from /lib/libc.so.6
> 0805eb9c closeServer () at agShell.c:66
> 4008f2f5 exit () from /lib/libc.so.6
> 08060837 main (argc=6, argv=0xbffff264) at autogen.c:97
> 4007cbaf __libc_start_main () from /lib/libc.so.6

"closeServer" is a callback in the "atexit()" list:

> void
> closeServer( void )
> {
>     if (serverId == NULLPROCESS)
>         return;
> 
>     (void)kill( serverId, SIGKILL );
>     serverId = NULLPROCESS;
-->   (void)fclose( serverPair.pfRead ); <-- call in stack
>     (void)fclose( serverPair.pfWrite );
>     serverPair.pfRead = serverPair.pfWrite = (FILE*)NULL;
> }

The (edited, slightly) process status:

> $ ps -t pts/1 -l
>   F S   PID  PPID ADDR SZ WCHAN  TTY   CMD
> 000 S  1393  1392 -   383 rt_sig pts/1 ksh
> 404 Z 13156 13155 -     0 do_exi pts/1 sh <defunct>
> 000 T 13155  1393 -  1005 do_sig pts/1 ag

Things to note about the program:

1.  The "serverId" process was fork()-ed with different ends of
    two separate "pipe(2)" calls for STDIN_FILENO and STDOUT_FILENO.
    These fileno's were fdopen-ed to create "pfRead" and "pfWrite".

2.  The program seg-faulted before this, calling gh_eval_str() to
    retrieve the value of a scheme variable, via:  "(. var-name)".
    The variable exists, so likely there is some internal issue.

3.  The seg-fault was handled with a siglongjump back to main(),
    with an immediate call to exit(3).

============

So, we have all kinds of issues here.  The main one is this:
How can one reliably clean up in a signal handler?  If there
are hidden pthread locks being held by a hung thread and those
locks are needed for cleanup, what do you do?  How do you
detect the issue and just let the kernel clean everything up?

My short-term hackaround will be to not close the pipes when
I am in "exit" processing.  (I close the server for other reasons,
too.)  I don't like that, though.

                 reply	other threads:[~2001-10-20 18:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3BD16577.5093D070@pacbell.net \
    --to=bkorb@pacbell.net \
    --cc=bug-glibc@gnu.org \
    --cc=guile-user@gnu.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox