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 17:19:12 +0000 Message-ID: <20140104171912.2967969d@bother.homenet> References: <20140103233407.36382e5f@bother.homenet> <87ha9kipjl.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 1388855964 3134 80.91.229.3 (4 Jan 2014 17:19:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 4 Jan 2014 17:19:24 +0000 (UTC) Cc: guile-user@gnu.org To: ludo@gnu.org (Ludovic =?ISO-8859-1?B?Q291cnTocw==?=) Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Jan 04 18:19:30 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 1VzUsi-0005mV-Ec for guile-user@m.gmane.org; Sat, 04 Jan 2014 18:19:28 +0100 Original-Received: from localhost ([::1]:55225 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VzUsi-0001qa-0U for guile-user@m.gmane.org; Sat, 04 Jan 2014 12:19:28 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55559) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VzUsV-0001q6-OZ for guile-user@gnu.org; Sat, 04 Jan 2014 12:19:20 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VzUsP-0006k8-4H for guile-user@gnu.org; Sat, 04 Jan 2014 12:19:15 -0500 Original-Received: from smtpout2.wanadoo.co.uk ([80.12.242.42]:36476 helo=smtpout.wanadoo.co.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VzUsO-0006ju-TV for guile-user@gnu.org; Sat, 04 Jan 2014 12:19:09 -0500 Original-Received: from bother.homenet ([95.146.112.60]) by mwinf5d30 with ME id 9tK71n00H1JEVaP03tK8YM; Sat, 04 Jan 2014 18:19:08 +0100 Original-Received: from bother.homenet (localhost [127.0.0.1]) by bother.homenet (Postfix) with ESMTP id 1E76A88504; Sat, 4 Jan 2014 17:19:12 +0000 (GMT) In-Reply-To: <87ha9kipjl.fsf@gnu.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.42 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:10975 Archived-At: On Sat, 04 Jan 2014 01:00:46 +0100 ludo@gnu.org (Ludovic Court=C3=A8s) wrote: > Chris Vine skribis: >=20 > > 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; > > } >=20 > This should work (but see below.) In fact, this is what > test-pthread-create-secondary.c tests (in Guile=E2=80=99s test suite.) >=20 > It may fail if libgc was built without pthread support, or if it=E2=80=99= s an > old version (older than 7.2alpha6). Could you check that? >=20 > 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. I am using gc-7.2d, and objdump -p shows that libgc.so.1 has a hard linking dependency on libpthread, so it looks as if it is compiled with thread support. You will see from later postings that this problem can be avoided by allowing one thread to initialize scm_with_guile() and scm_c_eval_string() to completion before any others attempt to do so. Chris