From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: mhw@netris.org Newsgroups: gmane.lisp.guile.devel Subject: Re: Need to block SIGCHLD in libgc and guile internal threads Date: Fri, 29 Aug 2014 13:36:52 -0400 Message-ID: <87mwan19l7.fsf@netris.org> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1409333865 6577 80.91.229.3 (29 Aug 2014 17:37:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 29 Aug 2014 17:37:45 +0000 (UTC) Cc: guile-devel To: Doug Evans Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Aug 29 19:37:39 2014 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XNQ7D-0004iC-7v for guile-devel@m.gmane.org; Fri, 29 Aug 2014 19:37:35 +0200 Original-Received: from localhost ([::1]:43484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XNQ7C-0001sn-QU for guile-devel@m.gmane.org; Fri, 29 Aug 2014 13:37:34 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37674) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XNQ72-0001rO-VK for guile-devel@gnu.org; Fri, 29 Aug 2014 13:37:31 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XNQ6w-0008MC-NL for guile-devel@gnu.org; Fri, 29 Aug 2014 13:37:24 -0400 Original-Received: from world.peace.net ([96.39.62.75]:41702) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XNQ6w-0008KH-Iv for guile-devel@gnu.org; Fri, 29 Aug 2014 13:37:18 -0400 Original-Received: from pool-74-104-33-122.bstnma.east.verizon.net ([74.104.33.122] helo=jojen) by world.peace.net with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1XNQ6e-0007Am-PP; Fri, 29 Aug 2014 13:37:01 -0400 In-Reply-To: (Doug Evans's message of "Tue, 26 Aug 2014 01:14:46 -0700") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 96.39.62.75 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:17376 Archived-At: Doug Evans 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