Jeremy, Eric, Thanks for your replies. Actually, I was able to get an answer a month ago, on perl5-porters. A discussion ensued, and I had a few other issues to resolve (such as perl 5.8.7 not allowing me to SvSHARE() a code reference).
For reference, that thread can be found here: http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2005-12/msg00497.html ...and the resulting (working) multithreaded code is at: http://search.cpan.org/~dpavlin/Fuse-0.07_3/ My only current gripe is that I have to use symbolic references (strings like "main::read_callback") to the callback functions. If anyone can figure out a way to SvSHARE() an actual code reference or closure or something like that, I'd be very grateful. :) Mark Jeremy White wrote: > >>> Recently, I noticed a blurb in perlguts which said all I had to do was >>> do PERL_SET_CONTEXT() and everything would be happy. (This perlguts >>> entry seems unclear as to whether this will work for concurrent calls, >>> or just for the occasional call on its own.) So I tried it. And >>> everything does work, if I put a lock around the whole thing. It >>> crashes horribly if I call into it multiple times concurrently. >>> >>> So, I did a little more research. It looks like I have to call >>> perl_clone(), but that crashes when I call into it concurrently, too. >>> And this time I have an additional problem: none of the arguments get >>> passed down to the callback sub! > > > Ok - this works for me (both Win32 and Linux). > > As early as you can perform a clone on the main thread, then save this > cloned Perl for later use. When you start spawning your worker threads, > you need to clone from the saved clone. You will also need a mutex > around your cloning logic. Some rough code: > > > PerlInterpreter* ClonePerl() { > //lock the mutex before we do anything > PerlInterpreter *NewPerl; > PerlInterpreter *my_perl; > pthread_mutex_lock(&CloneMutex); > PERL_SET_CONTEXT(savedPerlClone); > NewPerl = perl_clone(savedPerlClone,XXX); //XXX your flags > //you would check if NewPerl is valid... > //unlock the mutex > pthread_mutex_unlock(&CloneMutex); > //return the new perl > return NewPerl; > } > > > void worker() { > //worker thread init > PerlInterpreter* my_perl; > my_perl = ClonePerl(); > //each worker now has it's own perl, and you can do what you want to it:) > } > > Cheers, > > jez. > >