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 12:44:59 +0000 Message-ID: <20140104124459.6c604ae1@bother.homenet> References: <20140103233407.36382e5f@bother.homenet> <8738l41p8r.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 1388839511 842 80.91.229.3 (4 Jan 2014 12:45:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 4 Jan 2014 12:45:11 +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 13:45:17 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 1VzQbM-00060s-Ub for guile-user@m.gmane.org; Sat, 04 Jan 2014 13:45:17 +0100 Original-Received: from localhost ([::1]:54187 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VzQbM-0007aH-KQ for guile-user@m.gmane.org; Sat, 04 Jan 2014 07:45:16 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VzQb9-0007Vb-Hh for guile-user@gnu.org; Sat, 04 Jan 2014 07:45:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VzQb4-00012t-5X for guile-user@gnu.org; Sat, 04 Jan 2014 07:45:03 -0500 Original-Received: from smtpout5.wanadoo.co.uk ([80.12.242.80]:34954 helo=smtpout.wanadoo.co.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VzQb3-00012i-R3 for guile-user@gnu.org; Sat, 04 Jan 2014 07:44:58 -0500 Original-Received: from bother.homenet ([95.146.112.60]) by mwinf5d63 with ME id 9oku1n00F1JEVaP03okvei; Sat, 04 Jan 2014 13:44:56 +0100 Original-Received: from bother.homenet (localhost [127.0.0.1]) by bother.homenet (Postfix) with ESMTP id 11FA688504; Sat, 4 Jan 2014 12:44:59 +0000 (GMT) In-Reply-To: <8738l41p8r.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.80 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:10971 Archived-At: On Fri, 03 Jan 2014 20:59:16 -0500 Mark H Weaver wrote: > Chris Vine writes: > > I am having problems using libguile in a multi-threaded environment, > > which boils down to the following small test case, which fails with > > a segmentation fault with guile-2.0.9: > > I've recently noticed that the module loading process in Guile is not > thread safe. I hope to fix this in the next month or two, but for now > I'd recommend that one thread should initialize Guile and load the > modules that will be needed, before allowing multiple threads to enter > Guile mode. There is something even more bizarre than as reported in the exchange with Maciej. The further test case below prints: Hello 20 20 I would have expected: Hello 10 20 It seems as if top level variables in code evaluated by scm_c_eval_string() are shared between concurrently running threads. Is this really the intended behaviour (it is a significant and unexpected usability restriction)? Maciej (I hope that is your first name) can you reproduce this? Chris #include #include void *guile_wrapper1 (void *data) { scm_c_eval_string("(display \"Hello\n\")"); return NULL; } void *guile_wrapper2 (void *data) { scm_c_eval_string("(define val 10) (usleep 200000)(display val)(newline)"); return NULL; } void *guile_wrapper3 (void *data) { scm_c_eval_string("(usleep 100000) (define val 20) (display val)(newline)"); return NULL; } void *thread_func1 (void *data) { scm_with_guile(&guile_wrapper1, NULL); return NULL; } void *thread_func2 (void *data) { scm_with_guile(&guile_wrapper2, NULL); return NULL; } void *thread_func3 (void *data) { scm_with_guile(&guile_wrapper3, NULL); return NULL; } int main () { pthread_t thread1; pthread_t thread2; pthread_t thread3; pthread_create(&thread1, NULL, thread_func1, NULL); pthread_join(thread1, NULL); pthread_create(&thread2, NULL, thread_func2, NULL); pthread_create(&thread3, NULL, thread_func3, NULL); pthread_join(thread2, NULL); pthread_join(thread3, NULL); return 0; }