#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" #include "const-c.inc" MODULE = MyModule PACKAGE = MyModule INCLUDE: const-xs.inc int RegisterCB (SV *SubRef) CODE: ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(sv_2mortal(newSVpv("Some event",0))); XPUSHs(sv_2mortal(newSVpv("Some pdata",0))); PUTBACK; call_sv(SubRef, G_DISCARD); FREETMPS; LEAVE; RETVAL = 1; OUTPUT: RETVAL #### use MyModule; use warnings; #shared scalar $cb_done = 0; #This cb would be invoked by the cloned interpreter in the #C library. This works fine. sub cb_one { ($event, $pdata) = @_; #This line is printed. print "event : ", $event, "\n"; $cb_done = 1; } $status = MyModule::RegisterCB(\&main::cb_one); do { sleep (5); } until ($cb_done == 1); #This line is printed as $cb_done becomes 1 #in the main of the perl script print "CB was invoked : $cb_done\n"; #### C:\gash\MyModule>test.pl Name "main::pdata" used only once: possible typo at C:\gash\MyModule\test.pl line 11. Name "main::status" used only once: possible typo at C:\gash\MyModule\test.pl line 17. event : Some event CB was invoked : 1