Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

perlembed: Maintaining Multiple Interpreter Instances in Different Threads on Windows Server 2003

by hackdaddy (Hermit)
on Jan 19, 2006 at 01:18 UTC ( [id://524103]=perlquestion: print w/replies, xml ) Need Help??

hackdaddy has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing a multi-threaded Windows Service in C and I want to create a new Perl interpreter in each thread I create. The problem is that the perlembed docs only show how to interleave two Perl interpreters in one thread.

Has any one created multiple interpreters in different threads under Windows before? I'm not sure if my ActiveState Perl build can support this. I suppose I could run Perl in a new process in the thread instead. It would be cool if I could do this with the ActiveState Perl build without rebuilding.

From perlembed docs: "Using -Dusethreads -Duseithreads rather than -Dusemultiplicity is more appropriate if you intend to run multiple interpreters concurrently in different threads, because it enables support for linking in the thread libraries of your system with the interpreter."

Summary of my perl5 (revision 5 version 8 subversion 7) configuration: Platform: osname=MSWin32, osvers=5.0, archname=MSWin32-x86-multi-thread uname='' config_args='undef' hint=recommended, useposix=true, d_sigaction=undef usethreads=define use5005threads=undef useithreads=define usemulti +plicity=define useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cl', ccflags ='-nologo -Gf -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D +_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DBUILT_BY_ACTIVESTATE -DNO_HA +SH_SEED -DU SE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PER +LIO -DPERL_MSVCRT_READFIX', ... Characteristics of this binary (from libperl): Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES USE_SITECUSTOMIZE PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS ... Built under MSWin32 Compiled at Jun 6 2005 13:36:37 .


Update: I have the multiple threads working (that is, until there is a collision in the Perl code), and I preface the embedded with PERL_SET_CONTEXT(). The first thread may work to completion, but the others are causing access violations in the following Perl functions:

perl_parse
eval_pv
perl_destruct

From perlembed docs: "Note the calls to PERL_SET_CONTEXT(). These are necessary to initialize the global state that tracks which interpreter is the ``current'' one on the particular process or thread that may be running it. It should always be used if you have more than one interpreter and are making perl API calls on both interpreters in an interleaved fashion."
  • Comment on perlembed: Maintaining Multiple Interpreter Instances in Different Threads on Windows Server 2003
  • Download Code

Replies are listed 'Best First'.
Re: perlembed: Maintaining Multiple Interpreter Instances in Different Threads on Windows Server 2003
by Anonymous Monk on Oct 18, 2016 at 19:20 UTC
    Was this ever answered? I have the exact same problem.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://524103]
Approved by planetscape
Front-paged by inman
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-20 14:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found