[cl-gd-devel] thread safety in cl-gd
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
Hi Alain, On Fri, 27 Jul 2007 16:02:04 +1000, Alain Picard <Alain.Picard@memetrics.com> 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.
Edi Weitz <edi@agharta.de> 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
On Fri, 27 Jul 2007 16:02:04 +1000, Alain Picard <Alain.Picard@memetrics.com> 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.
participants (2)
-
Alain Picard -
Edi Weitz