You can try posting this at <a href="http://perlmonks.org">perlmonks.org</a> or another option would be via IRC at #perl channel or there are some helpful folks on <a href="irc://irc.perl.org/%23sdl" class="podlinkurl">irc://irc.perl.org/%23sdl</a> . <br>
<br>Is your perl built with thread support ?<br><br>-Kiran<br><br><div class="gmail_quote">On Tue, Nov 3, 2009 at 4:34 AM, Sri <span dir="ltr"><<a href="mailto:w2learn@yahoo.com">w2learn@yahoo.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi,<br>
<br>
I'm trying to provide a Perl interface to a C library (event-driven).<br>
<br>
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.<br>
<br>
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.<br>
<br>
---using perl 5.8.8, compiled with multiplicity, default_context etc---<br>
<br>
void mythread_fn(void)<br>
{<br>
<br>
static PerlInterpreter *my_perl=NULL;<br>
<br>
my_perl = perl_alloc();<br>
PERL_SET_CONTEXT(my_perl);<br>
perl_construct(my_perl);<br>
perl_run(my_perl);<br>
<br>
while (1)<br>
{<br>
<br>
/* monitor for events */<br>
if (event == xyz)<br>
callback_handler(event);<br>
}<br>
<br>
perl_destruct(my_perl);<br>
perl_free(my_perl);<br>
}<br>
<br>
void callback_handler(int event)<br>
{<br>
dTHX;<br>
dSP;<br>
<br>
ENTER;<br>
SAVETMPS;<br>
<br>
SV * sv = disc_callback; /* saved earlier in an API call */<br>
if (sv == (SV*)NULL)<br>
croak("Internal error...\n");<br>
<br>
PUSHMARK(SP);<br>
XPUSHs(sv_2mortal(newSViv(event)));<br>
PUTBACK;<br>
<br>
/* Call the Perl sub */<br>
call_sv(sv, G_DISCARD); /* crashes as shown below in gdb */<br>
<br>
FREETMPS;<br>
LEAVE;<br>
}<br>
<br>
Part of gdb stacktrace.<br>
<br>
#0 Perl_pp_entersub (my_perl=0x6587b0) at pp_hot.c:2945<br>
#1 0x00000000004224f3 in S_call_body (my_perl=0x6587b0, myop=0x65a6e0,<br>
is_eval=1 '\001') at perl.c:2728<br>
#2 0x00000000004223c4 in Perl_call_sv (my_perl=0x6587b0, sv=0x635420, flags=2)<br>
at perl.c:2607<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
Bangalore-pm mailing list<br>
<a href="mailto:Bangalore-pm@pm.org">Bangalore-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/bangalore-pm" target="_blank">http://mail.pm.org/mailman/listinfo/bangalore-pm</a><br>
</blockquote></div><br>