[Bangalore-pm] Multiple perl interpreters : how to use correctly

Kiran Kumar mkirank at gmail.com
Tue Nov 3 08:07:59 PST 2009


You can try posting this at perlmonks.org or another option would be  via
IRC at #perl channel or there are some helpful folks on
irc://irc.perl.org/%23sdl   .

Is your perl built with thread support ?

-Kiran

On Tue, Nov 3, 2009 at 4:34 AM, Sri <w2learn at yahoo.com> wrote:

> Hi,
>
> I'm trying to provide a Perl interface to a C library (event-driven).
>
> The C library has APIs, ofcourse, but it also allows perl-subroutines to be
> registered as callbacks into the C library.  The C library has a thread that
> monitors external events and invokes the perl-sub callbacks.
>
> The default perl interpreter is executing the script (interpreter instance
> one).  The library thread, creates a new interpreter.  But, crashes in the
> call_sv().  If I execute the same code (call_handler below, unmodified) as
> part of an API call invoked from perl-script, it works just fine.  So, I
> feel I'm not initializing/using the 2nd instance correctly.  If anyone has
> pointers or other forums that may specialize in this topic, it would be
> great help.
>
> ---using perl 5.8.8, compiled with multiplicity, default_context etc---
>
> void mythread_fn(void)
> {
>
>         static PerlInterpreter *my_perl=NULL;
>
>         my_perl = perl_alloc();
>         PERL_SET_CONTEXT(my_perl);
>         perl_construct(my_perl);
>         perl_run(my_perl);
>
>         while (1)
>         {
>
>             /* monitor for events */
>             if (event == xyz)
>                 callback_handler(event);
>         }
>
>        perl_destruct(my_perl);
>        perl_free(my_perl);
> }
>
> void callback_handler(int event)
> {
>      dTHX;
>      dSP;
>
>      ENTER;
>      SAVETMPS;
>
>      SV * sv = disc_callback;  /* saved earlier in an API call */
>      if (sv == (SV*)NULL)
>         croak("Internal error...\n");
>
>      PUSHMARK(SP);
>      XPUSHs(sv_2mortal(newSViv(event)));
>      PUTBACK;
>
>      /* Call the Perl sub */
>      call_sv(sv, G_DISCARD);  /* crashes as shown below in gdb */
>
>      FREETMPS;
>      LEAVE;
> }
>
> Part of gdb stacktrace.
>
> #0  Perl_pp_entersub (my_perl=0x6587b0) at pp_hot.c:2945
> #1  0x00000000004224f3 in S_call_body (my_perl=0x6587b0, myop=0x65a6e0,
>    is_eval=1 '\001') at perl.c:2728
> #2  0x00000000004223c4 in Perl_call_sv (my_perl=0x6587b0, sv=0x635420,
> flags=2)
>    at perl.c:2607
>
>
>
>
> _______________________________________________
> Bangalore-pm mailing list
> Bangalore-pm at pm.org
> http://mail.pm.org/mailman/listinfo/bangalore-pm
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/bangalore-pm/attachments/20091103/8c7bb0a0/attachment.html>


More information about the Bangalore-pm mailing list