[JD, please keep the thread on the list. Thanks]
JD Brennan wrote:
Stas Bekman wrote:
I'm not familiar with activeperl, but perl_clone and perl_alloc aren't the
same thing. You must run perl_clone if you want to start an ithread.
So what are the tradeoffs/advantages of perl_alloc() vs perl_clone()?
perl_clone clones an existing perl interpreter. perl_alloc creates a fresh
one. in the latter case a newly created perl will have nothing to do with
the parent perl. In the former case they will share the opcode tree and
you will be able to have shared variables.
Does perl_clone() create a thread? If I've already created a separate
pthread, then do I have to call perl_alloc() and not use perl_clone()?
a pthread thread has nothing to do with perl ithread. perl_clone creates a
perl interpreter cloning the existing parent interpreter. You can have as
many as you want. e.g. 1 perl interpreter and 10 pthreads, or 10 perl
interpreters and 1 pthread.
If you want to attach an interpeter to a thread, you need to read
ext/threads/threads.xs
Normally if you want to clone an interpreter your program goes like.
int main(int argc, char **argv, char **env)
{
char *embedding[] = { "", "-le", "0" };
dTHX;
PerlInterpreter *one_perl = perl_alloc();
PerlInterpreter *two_perl;
aTHX = one_perl;
PERL_SET_CONTEXT(aTHX);
perl_construct(one_perl);
perl_parse(one_perl, xs_init, 3, embedding, (char **)NULL);
/* DynaLoader must be preloaded before perl_clone, if DynaLoader
* is to be required later */
eval_pv("require DynaLoader;", TRUE);
two_perl = perl_clone(one_perl, CLONEf_KEEP_PTR_TABLE);
...
P.S. I just used ActivePerl since it comes with usethreads and useithreads
defined, so I didn't have to build Perl myself. I can certainly
grab the standard distribution and build it myself. I guess that
might have different behavior. Probably worth trying.
--
_____________________________________________________________
Stas Bekman mailto:[EMAIL PROTECTED] http://stason.org/
MailChannels: Assured Messaging(TM) http://mailchannels.com/
The "Practical mod_perl" book http://modperlbook.org/
http://perl.apache.org/ http://perl.org/ http://logilune.com/