From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chris Vine Newsgroups: gmane.lisp.guile.user Subject: Re: libguile thread safety Date: Sat, 4 Jan 2014 21:01:18 +0000 Message-ID: <20140104210118.3564073f@bother.homenet> References: <20140103233407.36382e5f@bother.homenet> <8738l41p8r.fsf@netris.org> <20140104124459.6c604ae1@bother.homenet> <87y52vzgfc.fsf@netris.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1388869291 6983 80.91.229.3 (4 Jan 2014 21:01:31 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 4 Jan 2014 21:01:31 +0000 (UTC) Cc: guile-user@gnu.org To: Mark H Weaver Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Jan 04 22:01:37 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 1VzYLh-0001Bj-H4 for guile-user@m.gmane.org; Sat, 04 Jan 2014 22:01:37 +0100 Original-Received: from localhost ([::1]:55734 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VzYLh-0006PL-6x for guile-user@m.gmane.org; Sat, 04 Jan 2014 16:01:37 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60433) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VzYLT-0006P2-0q for guile-user@gnu.org; Sat, 04 Jan 2014 16:01:29 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VzYLM-0007qc-TF for guile-user@gnu.org; Sat, 04 Jan 2014 16:01:22 -0500 Original-Received: from smtpout4.wanadoo.co.uk ([80.12.242.68]:49932 helo=smtpout.wanadoo.co.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VzYLM-0007qU-Mw for guile-user@gnu.org; Sat, 04 Jan 2014 16:01:16 -0500 Original-Received: from bother.homenet ([95.146.112.60]) by mwinf5d54 with ME id 9x1D1n00N1JEVaP03x1EgE; Sat, 04 Jan 2014 22:01:15 +0100 Original-Received: from bother.homenet (localhost [127.0.0.1]) by bother.homenet (Postfix) with ESMTP id 24FA088504; Sat, 4 Jan 2014 21:01:18 +0000 (GMT) In-Reply-To: <87y52vzgfc.fsf@netris.org> X-Mailer: Claws Mail 3.9.2 (GTK+ 2.24.22; i686-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 80.12.242.68 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:10977 Archived-At: On Sat, 04 Jan 2014 14:37:59 -0500 Mark H Weaver wrote: > Indeed, top-level bindings are always looked up in the "current > module". Each thread has its own "current module", but > 'scm_with_guile' initially sets the current module to (guile-user). > That's usually desirable, because you may have bound your own > application-specific procedures and global variables in (guile-user), > and you want all threads to have access to those by default. > > The usual way to make thread-local variables in Guile is to use > parameters[1] or fluids[2]. It's rather unusual to create fresh > modules for each thread, but if you really want to do that you can > start each thread by evaluating "(set-current-module > (make-fresh-user-module))". > > [1] API Reference > Scheduling > Parameters (section 6.21.8) > [2] API Reference > Scheduling > Fluids and Dynamic States (section > 6.21.7) That's great. Both using parameters and changing the current module to one obtained by make-fresh-user-module works, but changing the current module is the best fit for what I want to do with this. Is it efficiency concerns that make you think it unusual, or just that the use case is unusual? (For anyone calling scm_c_eval_string() in a multi-threaded program, as opposed to evaluating eval at the REPL, I should have thought a fresh module was just what they wanted.) make-fresh-user-module is not documented. It might be worth adding it to the documentation. Chris