From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] Fix gc.test "after-gc-hook gets called" failures Date: Tue, 16 Apr 2019 17:38:00 -0400 Message-ID: <87k1ft6370.fsf@netris.org> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="69954"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) Cc: guile-devel@gnu.org, 31776@debbugs.gnu.org To: Andrea Azzarone Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Apr 16 23:39:56 2019 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hGVo4-000I2H-8q for guile-devel@m.gmane.org; Tue, 16 Apr 2019 23:39:56 +0200 Original-Received: from localhost ([127.0.0.1]:43167 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGVo3-0007nt-8L for guile-devel@m.gmane.org; Tue, 16 Apr 2019 17:39:55 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:39208) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGVnu-0007nS-IV for guile-devel@gnu.org; Tue, 16 Apr 2019 17:39:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hGVnn-0007dA-2D for guile-devel@gnu.org; Tue, 16 Apr 2019 17:39:41 -0400 Original-Received: from world.peace.net ([64.112.178.59]:52898) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hGVnj-0007bb-7U for guile-devel@gnu.org; Tue, 16 Apr 2019 17:39:37 -0400 Original-Received: from mhw by world.peace.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hGVnh-0006mM-VI; Tue, 16 Apr 2019 17:39:34 -0400 In-Reply-To: (Andrea Azzarone's message of "Thu, 11 Apr 2019 16:43:23 +0100") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 64.112.178.59 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.lisp.guile.devel:19888 Archived-At: Hi Andrea, Andrea Azzarone writes: > "after-gc-hook gets called" test randomly fails as reported > downstream, for example: > - https://debbugs.gnu.org/cgi/bugreport.cgi?bug=31776 > - https://bugs.launchpad.net/ubuntu/+source/guile-2.2/+bug/1823459 > > I'm attaching a patch that seems to fix the failures. > > From 2efba337d5b636cd975260f19ea74e27ecf0ca17 Mon Sep 17 00:00:00 2001 > From: Andrea Azzarone > Date: Thu, 11 Apr 2019 16:30:58 +0100 > Subject: Fix gc.test "after-gc-hook gets called" failures > > * libguile/scmsigs.c: Call scm_async_tick to give any pending asyncs a chance to > run before we block indefinitely waiting for a signal to arrive. Thanks for this. I pushed your commit (with minor reformatting) to our 'stable-2.2' branch as commit 546b0e87294b837ec29164d87cf17102e9aeee0c. I believe that this will prevent the problem from happening in the most common cases, e.g. when there's only one user-visible thread, or when there are no long-sleeping user-visible threads. However, it occurs to me that in a multithreaded Guile program, a user thread might trigger a GC and then sleep for a long time, without calling 'scm_async_tick' in between. If we're unlucky and the 'after_gc_async' gets queued in the wrong thread, it might be a long time before the hook runs. Fundamentally, the problem we face here is similar to the thorny problems faced with finalizers and signal handlers: we must choose a proper time and context for them to be run safely, when the data they need to access is in a consistent state, etc. To deal with the issues around finalizers, Guile recently gained a finalizer thread. It may be that we should arrange to run the 'after_gc_async' in the finalizer thread as well, instead of whatever random thread we happen to be in when GC is triggered. Thoughts? Regards, Mark