From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Newsgroups: gmane.lisp.guile.user Subject: Re: libguile thread safety Date: Sat, 04 Jan 2014 01:00:46 +0100 Message-ID: <87ha9kipjl.fsf@gnu.org> References: <20140103233407.36382e5f@bother.homenet> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1388848672 27017 80.91.229.3 (4 Jan 2014 15:17:52 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 4 Jan 2014 15:17:52 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Jan 04 16:17: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 1VzSz7-0006h9-Ru for guile-user@m.gmane.org; Sat, 04 Jan 2014 16:17:57 +0100 Original-Received: from localhost ([::1]:54795 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VzSz7-0008Cr-Ef for guile-user@m.gmane.org; Sat, 04 Jan 2014 10:17:57 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59097) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VzEfs-0001yK-Q3 for guile-user@gnu.org; Fri, 03 Jan 2014 19:01:14 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VzEfm-0006N3-Pk for guile-user@gnu.org; Fri, 03 Jan 2014 19:01:08 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:53286) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VzEfm-0006Mv-IQ for guile-user@gnu.org; Fri, 03 Jan 2014 19:01:02 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1VzEfj-0002Xf-V8 for guile-user@gnu.org; Sat, 04 Jan 2014 01:00:59 +0100 Original-Received: from reverse-83.fdn.fr ([80.67.176.83]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 04 Jan 2014 01:00:59 +0100 Original-Received: from ludo by reverse-83.fdn.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 04 Jan 2014 01:00:59 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 46 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: reverse-83.fdn.fr X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 15 =?utf-8?Q?Niv=C3=B4se?= an 222 de la =?utf-8?Q?R?= =?utf-8?Q?=C3=A9volution?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 83C4 F8E5 10A3 3B4C 5BEA D15D 77DD 95E2 EA52 ECF4 X-OS: x86_64-unknown-linux-gnu User-Agent: Gnus/5.130007 (Ma Gnus v0.7) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:Lw50MjPMt+1XrdODfG+llFsWfus= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-Mailman-Approved-At: Sat, 04 Jan 2014 10:17:48 -0500 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:10973 Archived-At: Hi, Chris Vine skribis: > 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: > > #include > #include > > void *guile_wrapper (void *data) { > scm_c_eval_string ("(display \"Hello\n\")"); > return NULL; > } > > void *thread_func (void *data) { > scm_with_guile (&guile_wrapper, NULL); > return NULL; > } > > int main () { > pthread_t thread1; > pthread_t thread2; > > pthread_create (&thread1, NULL, thread_func, NULL); > pthread_create (&thread2, NULL, thread_func, NULL); > > pthread_join (thread1, NULL); > pthread_join (thread2, NULL); > return 0; > } This should work (but see below.) In fact, this is what test-pthread-create-secondary.c tests (in Guile’s test suite.) It may fail if libgc was built without pthread support, or if it’s an old version (older than 7.2alpha6). Could you check that? However, ports themselves are not thread-safe in 2.0, and the code above has several threads writing to the current output port, which is a problem. When an application has several threads using the same port, it must do its own locking currently. Thanks, Ludo’.