[jifty-devel] jifty segfault with threads

Matt Zagrabelny mzagrabe at d.umn.edu
Thu Dec 9 18:08:11 EST 2010


On Thu, Dec 9, 2010 at 3:57 PM, Stanislav Sinyagin <ssinyagin at yahoo.com> wrote:
> well, I've done a lot with threading in torrus.org :)
>
> I didn't try it with jifty, but I guess your fault is that you:
> 1) initialize Jifty while you're single-threaded
> 2) launch a thread afterward.
>
> Creating a thread is an expensive process in Perl, and it tries to duplicate
> all memory structures. So, in your case, you have already lots of initialized
> memory and a database handle, and then Perl tries to clone everything,
> and it's not always happening well :)
>
>
> If you really want to do it, then at the beginning of your program you
> launch all your threads, then in only one thread you do
>
> require('Jifty');
> and do all your jifty-related stuff in this thread. Tthis could also be the
> parent thread. Important that you don't create new threads from a thread
> where Jifty is initialized.
>
> then it should work, in theory :)
>
> but I believe you can easily avoid multithreading in most cases.
>
> Another point -- if you execute some non-threadsafe library from multiple
> threads, you just protect that piece with semaphores.
>
> Example:
> XML::LibXML is not thread-safe, as well as the underlying Gnome libxml2.
> http://goo.gl/lHHVZ
> Line 505 onwards:
> here I screen LibXML calls with a semaphore, ensuring that only one thread
> uses the library at a time, from the XML file opening to its closing.
>
>
> I hope this helps :)

It does.

Regarding launching all my threads first, that doesn't quite work.
Part of the Jifty magic was a BEGIN block, which would get executed
first regardless of when I started the threads. Unless of course, I
could create the threads in a BEGIN block, which I might do.

I think I can work my program as normal, threads and all, and do the
Jifty stuff in the main thread. Initial results are positive. :)

A couple questions, though. I am getting a couple warnings:

(in cleanup) Can't call method "_warning_action" on an undefined value
at /usr/share/perl5/Jifty/Logger.pm line 121 during global
destruction.

And the other:

WARN - Overwriting an existing Template::Declare->around_template at
/usr/share/perl5/Jifty/Plugin/Halo.pm line 33.

What is the best way to correct those warnings?

Thanks for the help,

-matt


More information about the jifty-devel mailing list