From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] Make guardians and (ice-9 popen) thread-safe Date: Sat, 23 Nov 2013 19:18:06 -0500 Message-ID: <87mwkuzm81.fsf@netris.org> References: <877gc66xw9.fsf@netris.org> <877gbzyx7g.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1385252349 10854 80.91.229.3 (24 Nov 2013 00:19:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 24 Nov 2013 00:19:09 +0000 (UTC) Cc: guile-devel@gnu.org To: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Nov 24 01:19:13 2013 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 1VkNPt-0004Oj-G8 for guile-devel@m.gmane.org; Sun, 24 Nov 2013 01:19:13 +0100 Original-Received: from localhost ([::1]:45504 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VkNPs-0003mE-61 for guile-devel@m.gmane.org; Sat, 23 Nov 2013 19:19:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44107) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VkNPl-0003m6-49 for guile-devel@gnu.org; Sat, 23 Nov 2013 19:19:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VkNPf-0000p9-PK for guile-devel@gnu.org; Sat, 23 Nov 2013 19:19:05 -0500 Original-Received: from world.peace.net ([96.39.62.75]:53859) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VkNPf-0000gU-LT; Sat, 23 Nov 2013 19:18:59 -0500 Original-Received: from 209-6-91-212.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com ([209.6.91.212] helo=yeeloong) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1VkNPO-0002mF-AV; Sat, 23 Nov 2013 19:18:42 -0500 In-Reply-To: <877gbzyx7g.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Sat, 23 Nov 2013 16:06:11 +0100") 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:16761 Archived-At: Hi Ludovic, Thanks for the review! I incorporated your (excellent) suggestions, and pushed it to stable-2.0. ludo@gnu.org (Ludovic Court=C3=A8s) writes: >> From 13fcd175bc31b5df400dd518836bdce32f32206a Mon Sep 17 00:00:00 2001 >> From: Mark H Weaver >> Date: Sun, 17 Nov 2013 03:19:32 -0500 >> Subject: [PATCH 2/6] Block system asyncs while 'overrides_lock' is held. >> >> * libguile/procprop.c (scm_set_procedure_property_x): Block system >> asyncs while overrides_lock is held. Use dynwind block in case >> an exception is thrown. > > [...] > >> - scm_i_pthread_mutex_lock (&overrides_lock); >> + scm_dynwind_begin (0); >> + scm_i_dynwind_pthread_mutex_lock_with_asyncs (&overrides_lock); >> props =3D scm_hashq_ref (overrides, proc, SCM_BOOL_F); > > Could you recap why asyncs must be blocked here, and add it as a > comment? > > I would think that there=E2=80=99s no way =E2=80=98scm_hashq_ref=E2=80=99= can trigger an async > run, because it doesn=E2=80=99t call out to Scheme, does it? That's right, but in 'scm_set_procedure_property_x', 'scm_i_program_properties' is also called while the mutex is locked. 'scm_i_program_properties' calls out to the VM, so asyncs can be run. I encountered deadlocks from this exact scenario in my previous attempt to fix (ice-9 popen) thread safety. I added a comment. > Also, I wonder if this should rather be exposed as =E2=80=98%port-propert= y KEY=E2=80=99 > and =E2=80=98%set-port-property! PORT KEY VALUE=E2=80=99. Those two proc= edures could > eventually do any locking required. Good idea. Thanks! Mark