unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: mhw@netris.org
To: Doug Evans <xdje42@gmail.com>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: Need to block SIGCHLD in libgc and guile internal threads
Date: Fri, 29 Aug 2014 13:36:52 -0400	[thread overview]
Message-ID: <87mwan19l7.fsf@netris.org> (raw)
In-Reply-To: <CAP9bCMTCpRbQ2=frarOPHSghMUr4fbz=vFCuGjgN=JO9_3eG1g@mail.gmail.com> (Doug Evans's message of "Tue, 26 Aug 2014 01:14:46 -0700")

Doug Evans <xdje42@gmail.com> writes:

> I think(!) I understand why gdb is hanging when used with libgc 7.4.x.
> This is gdb bug 17247.
> https://sourceware.org/bugzilla/show_bug.cgi?id=17247#c30

[...]

> gdb/linux-nat.c calls sigsuspend when the inferior is running and gdb
> needs to wait for it to stop.
> gdb is waiting on a SIGCHLD at this point.
>
> However, if the SIGCHLD goes to a different thread, say the guile
> finalizer thread or a libgc marker thread then the sigsuspend that gdb
> calls doesn't wake up and gdb is hung.
>
> So question: Any suggestions for how to approach this?

[...]

> I think there's a general issue here that these threads should block
> every signal they're not expecting,

Agreed.  Threads that Guile creates implicitly should block every signal
that they're not expecting.

> diff --git a/libguile/finalizers.c b/libguile/finalizers.c
> index 82f292c..95a022c 100644
> --- a/libguile/finalizers.c
> +++ b/libguile/finalizers.c
> @@ -239,6 +239,12 @@ finalization_thread_proc (void *unused)
>  static void*
>  run_finalization_thread (void *arg)
>  {
> +  {
> +    sigset_t blocked_mask;
> +    sigemptyset (&blocked_mask);
> +    sigaddset (&blocked_mask, SIGCHLD);
> +    sigprocmask (SIG_BLOCK, &blocked_mask, NULL);
> +  }
>    return scm_with_guile (finalization_thread_proc, arg);
>  }

This code should be harmonized with the code at the top of
'signal_delivery_thread' in scmsigs.c:

--8<---------------cut here---------------start------------->8---
static SCM
signal_delivery_thread (void *data)
{
  int sig;
#if HAVE_PTHREAD_SIGMASK  /* not on mingw, see notes above */
  sigset_t all_sigs;
  sigfillset (&all_sigs);
  /* On libgc 7.1 and earlier, GC_do_blocking doesn't actually do
     anything.  So in that case, libgc will want to suspend the signal
     delivery thread, so we need to allow it to do so by unmasking the
     suspend signal.  */
  sigdelset (&all_sigs, GC_get_suspend_signal ());
  scm_i_pthread_sigmask (SIG_SETMASK, &all_sigs, NULL);
#endif
--8<---------------cut here---------------end--------------->8---

On master, where we now require gc-7.2 or later, I guess we should be
able to simplify this and block all signals.

However, it's not clear how to backport this to stable-2.0, which does
not even have a finalization thread, and yet gdb bug 17247 occurs with
Guile 2.0.11.  Any idea how to prevent the problem on stable-2.0?

     Thanks,
       Mark



  parent reply	other threads:[~2014-08-29 17:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-26  8:14 Need to block SIGCHLD in libgc and guile internal threads Doug Evans
2014-08-26 16:41 ` Doug Evans
2014-08-29 17:36 ` mhw [this message]
2014-08-30 17:40   ` Doug Evans

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

  List information: https://www.gnu.org/software/guile/

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

  git send-email \
    --in-reply-to=87mwan19l7.fsf@netris.org \
    --to=mhw@netris.org \
    --cc=guile-devel@gnu.org \
    --cc=xdje42@gmail.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).