Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" CV* callback_ref; int runCallback(const char* param) { int count; int answer; dSP; ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(sv_2mortal(newSVpv(param, 0))); PUTBACK; count = call_sv((SV*)callback_ref, G_SCALAR); SPAGAIN; if (count != 1) croak("Uncknown return value format. Returned %d params instid 1", + count); answer = POPi; FREETMPS; LEAVE; return answer; } MODULE = Callback PACKAGE = Callback void registCallback(cb) CV* cb; PROTOTYPE: $ PPCODE: callback_ref = cb; void runCallback(param) const char* param; PROTOTYPE: $ PPCODE: XPUSHs(sv_2mortal( newSViv(runCallback(param)) ));
package Callback; use 5.010000; use threads; use threads::shared; use strict; use warnings; require Exporter; use AutoLoader qw(AUTOLOAD); our @ISA = qw(Exporter); our $VERSION = '0.01'; require XSLoader; XSLoader::load('Callback', $VERSION); sub new { my $invocant = shift; my $callback_ref = shift; $invocant = ref $invocant if ref $invocant; registCallback($callback_ref); my $self = &share({}); return bless $self, $invocant; } sub run { my $self = shift; my $param = shift; runCallback($param); } 1;
#!/usr/bin/env perl use strict; use lib qw(./Callback/build/lib/perl5/i386-linux-thread-multi/); use threads; use threads::shared; use Data::Dumper; use Callback; use constant MESSAGE => "Hellow world!!!\n"; my $obj = new Callback (\&printHellow); my $thread = threads->create(sub {$obj->run(&MESSAGE)}) or exit(1); $thread->join(); sub printHellow { my $message = shift; print "MESSAGE: $message\n"; }
MESSAGE: panic: free from wrong pool during global destruction.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: xs, threads and panic
by BrowserUk (Patriarch) on May 20, 2009 at 07:48 UTC | |
by Anonymous Monk on May 20, 2009 at 10:16 UTC | |
by BrowserUk (Patriarch) on May 20, 2009 at 13:22 UTC | |
by Anonymous Monk on May 20, 2009 at 13:32 UTC | |
by BrowserUk (Patriarch) on May 20, 2009 at 13:37 UTC | |
|
Re: xs, threads and panic
by dave_the_m (Monsignor) on May 20, 2009 at 09:57 UTC | |
by Anonymous Monk on May 20, 2009 at 10:56 UTC | |
by dave_the_m (Monsignor) on May 20, 2009 at 13:26 UTC | |
by Anonymous Monk on May 20, 2009 at 14:38 UTC | |
|
Re: xs, threads and panic
by Cuba (Initiate) on May 20, 2009 at 18:29 UTC |