From Alain.Picard at memetrics.com Fri Jul 27 06:02:04 2007 From: Alain.Picard at memetrics.com (Alain Picard) Date: Fri, 27 Jul 2007 16:02:04 +1000 Subject: [cl-gd-devel] thread safety in cl-gd Message-ID: <87ir8675b7.fsf@memetrics.com> Dear all, I'm wondering if cl-gd has been thoroughly tested for thread safety? I've experienced a couple of segfaults here and there, apparently at random, in libgd. Cursory inspection of the code seems to suggest, for instance, that *transfomers* is not safe; the only references to this variable I see are in specials.lisp: (defvar *transformers* nil "Stack of currently active transformer objects.") and in WITH-TRANFORMATION, which does not create a new binding for *transformers*, but rather just pushes a new transformation onto the global *transformers*. Am I reading this right? It seems to me that two different lispworks threads could run in such a way so that 1 thread inadvertently starts running with transformers that another thread establishes then gets swapped out. Comments? Alain Picard -- Please read about why Top Posting is evil at: http://en.wikipedia.org/wiki/Top-posting and http://www.dickalba.demon.co.uk/usenet/guide/faq_topp.html Please read about why HTML in email is evil at: http://www.birdhouse.org/etc/evilmail.html From edi at agharta.de Fri Jul 27 15:47:51 2007 From: edi at agharta.de (Edi Weitz) Date: Fri, 27 Jul 2007 17:47:51 +0200 Subject: [cl-gd-devel] thread safety in cl-gd In-Reply-To: <87ir8675b7.fsf@memetrics.com> (Alain Picard's message of "Fri, 27 Jul 2007 16:02:04 +1000") References: <87ir8675b7.fsf@memetrics.com> Message-ID: Hi Alain, On Fri, 27 Jul 2007 16:02:04 +1000, Alain Picard wrote: > I'm wondering if cl-gd has been thoroughly tested for thread safety? No, not really. I've sometimes used it in multi-threaded environments (without any issues), but I wouldn't count that as serious tests. > Cursory inspection of the code seems to suggest, for instance, that > *transfomers* is not safe; the only references to this variable I > see are in specials.lisp: > (defvar *transformers* nil > "Stack of currently active transformer objects.") > > and in WITH-TRANFORMATION, which does not create a new binding for > *transformers*, but rather just pushes a new transformation onto the > global *transformers*. > > Am I reading this right? It seems to me that two different > lispworks threads could run in such a way so that 1 thread > inadvertently starts running with transformers that another thread > establishes then gets swapped out. Right. It would certainly be better to rebind *TRANSFORMERS* here. I'll fix this. But this shouldn't be the reason for segfaults, should it? I'm wondering if libgd itself is thread-safe. From http://www.libgd.org/Main_Page it doesn't necessarily look as if it is. Cheers, Edi. From edi at agharta.de Sun Jul 29 16:40:33 2007 From: edi at agharta.de (Edi Weitz) Date: Sun, 29 Jul 2007 18:40:33 +0200 Subject: [cl-gd-devel] New release 0.5.6 (Was: thread safety in cl-gd) In-Reply-To: <87ir8675b7.fsf@memetrics.com> (Alain Picard's message of "Fri, 27 Jul 2007 16:02:04 +1000") References: <87ir8675b7.fsf@memetrics.com> Message-ID: On Fri, 27 Jul 2007 16:02:04 +1000, Alain Picard wrote: > Cursory inspection of the code seems to suggest, for instance, that > *transfomers* is not safe; the only references to this variable I > see are in specials.lisp: > (defvar *transformers* nil > "Stack of currently active transformer objects.") > > and in WITH-TRANFORMATION, which does not create a new binding for > *transformers*, but rather just pushes a new transformation onto the > global *transformers*. The new release rebinds *TRANSFORMATIONS* and thus should hopefully fix this issue. Thanks for the report, Edi. From Alain.Picard at memetrics.com Mon Jul 30 04:17:08 2007 From: Alain.Picard at memetrics.com (Alain Picard) Date: Mon, 30 Jul 2007 14:17:08 +1000 Subject: [cl-gd-devel] thread safety in cl-gd In-Reply-To: (Edi Weitz's message of "Fri\, 27 Jul 2007 17\:47\:51 +0200") References: <87ir8675b7.fsf@memetrics.com> Message-ID: <87r6mqeda3.fsf@memetrics.com> Edi Weitz writes: > > But this shouldn't be the reason for segfaults, should it? I'm > wondering if libgd itself is thread-safe. From > > http://www.libgd.org/Main_Page > > it doesn't necessarily look as if it is. The GD manual states: What's new in version 2.0.16? * Thread safety for freetype text output. Background: all gd functions were already thread safe, as long as only one thread manipulates each image -- except for gdImageStringFT and gdImageStringFTEx. and I'm only interested in having 1 lisp thread at a time manipulate an instance of CL-GD:*DEFAULT-IMAGE*, so it _seems_ to me that it's supposed to be OK. If I can't track down the segfaults, I might have to serialize all entry points into my image generation routines, which won't really be a problem in practice for my application. Oh, and thanks for the quick fix! -alain