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.user Subject: Re: libguile thread safety Date: Sun, 05 Jan 2014 12:37:29 -0500 Message-ID: <87k3eexrc6.fsf@netris.org> References: <20140103233407.36382e5f@bother.homenet> <8738l41p8r.fsf@netris.org> <20140104124459.6c604ae1@bother.homenet> <87y52vzgfc.fsf@netris.org> <20140104210118.3564073f@bother.homenet> <20140104233120.77b0edaa@bother.homenet> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1388943592 4885 80.91.229.3 (5 Jan 2014 17:39:52 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 5 Jan 2014 17:39:52 +0000 (UTC) Cc: guile-user@gnu.org To: Panicz Maciej Godek Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Jan 05 18:39:58 2014 Return-path: Envelope-to: guile-user@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 1Vzrg6-0005Tf-3t for guile-user@m.gmane.org; Sun, 05 Jan 2014 18:39:58 +0100 Original-Received: from localhost ([::1]:58845 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vzrg5-0007qU-Nm for guile-user@m.gmane.org; Sun, 05 Jan 2014 12:39:57 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57352) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vzrfp-0007nH-N9 for guile-user@gnu.org; Sun, 05 Jan 2014 12:39:47 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vzrfj-0007CZ-Ln for guile-user@gnu.org; Sun, 05 Jan 2014 12:39:41 -0500 Original-Received: from world.peace.net ([96.39.62.75]:38671) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vzrfj-0007CV-IG for guile-user@gnu.org; Sun, 05 Jan 2014 12:39:35 -0500 Original-Received: from 209-6-197-194.c3-0.smr-ubr2.sbo-smr.ma.cable.rcn.com ([209.6.197.194] helo=yeeloong) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1Vzrfb-0003by-M9; Sun, 05 Jan 2014 12:39:27 -0500 In-Reply-To: (Panicz Maciej Godek's message of "Sun, 5 Jan 2014 14:15:42 +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-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:10982 Archived-At: Panicz Maciej Godek writes: > 2014/1/5 Chris Vine : > >> I actually have a prototype working well now, apart from the module >> issue Mark Weaver referred to, which I have to say has not yet bitten me >> but no doubt might. > > If you are worried about this, you could try to take your own > precautions and redefine the "use-modules" syntax (or others, like > "resolve-module", if you are planning to use them) to make sure that > it is thread safe. > > The sole act of redefinition would require you to create a new module like this: > (define-module (safe-modules) > #:use-module (ice-9 format) > #:replace ((safe-use-modules . use-modules))) > > (define-syntax-rule (safe-use-modules modules ...) > (begin > (format #t "loading modules ~a... " '(modules ...)) > (use-modules modules ...) > (format #t "done!\n"))) > > You'd need to replace the the messages with some thread > synchronization mechanism, to make sure that if one thread calls > "use-modules", all the others that would try to do that at that time > would have to wait. This wouldn't work. First of all, 'use-modules' is a macro, not a procedure, but more importantly, modules are autoloaded in many places deep in the guts of the system. Notice that Chris' test cases didn't use 'use-modules' at all. In fact, a module is autoloaded the first time 'scm_c_eval_string' is called. Also, there are potential deadlocks. We should just fix the problem properly, and that's what I intend to do. Mark