Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Unorthodox Embedding/XS madness!

by MZSanford (Curate)
on Oct 10, 2002 at 13:50 UTC ( #204176=note: print w/ replies, xml ) Need Help??


in reply to Unorthodox Embedding/XS madness!

I must say, i loved this post. This is how i learned embedding, and ran into many similar problems. The best companion i found is Extending and Embedding Perl (Manning). It covers alot of the small things that the perl docs don't.

The only thing i can say, from my experiance, is that using Perl from diffrent threads (not creating threads with use Threads, but diffrent threads in an embedding application) is a big no-no. I have not worked with perl 5.8, but if you are running under 5.6.1, i think you will find it does not claim to be thread-safe, and, well, isnt :(. Hopefully someone else will post and say i am wrong, but i am afraid you may have to marshall all Perl calls into one thread and work from there.

In a CB Style ...
MZSanford Raises glass
<MZSanford> Here's to hoping i am wrong


from the frivolous to the serious


Comment on Re: Unorthodox Embedding/XS madness!
Download Code
Re: Re: Unorthodox Embedding/XS madness!
by Ouroborous (Initiate) on Oct 10, 2002 at 17:31 UTC
    Thanks -- yeah, marshalling all the calls into one thread is what I had planned to do all along, ironically. This was just proof-of-concept code, so I hadn't bothered to put the call marshalling in place yet. I got thrown for a loop by the exception until I realized that the one thing I hadn't ruled out last night was threading issues.

    It was sort of a pain (for various reasons) to repro this in the actual embedded app, so I had created a "test app" that just embedded Perl the same way and called it directly. It didn't trap, which was frustrating. After I had my "threads epiphany", I added a couple lines of code to my test app to spawn the interpreter in another thread and hold it there until I signaled a shutdown. Then I called eval_pv() from the main thread and voila -- exception city. This was nice because the actual app was an injected DLL (long story) which made it VERY hard to debug the trap, whereas my test app was just a standalone executable, and it was a snap after the exception to step in and see where the interpreter was stashing the pointer to itself in thread-local storage. Oh well, live and learn.

    Well, it's good to know that it's not thread safe. That will hopefully keep me from shooting myself in the foot like this in the future. I can't wait until ActiveState gets their distro up to 5.8 -- I would REALLY like better built-in threading behavior (I'm assuming that since ithreads is included, the core Perl modules have been made thread-safe -- is this a reasonable assumption?)

    Thanks for the help and the pairs of eyes...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://204176]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (17)
As of 2014-08-01 13:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (20 votes), past polls