in reply to Re: Unorthodox Embedding/XS madness!
in thread Unorthodox Embedding/XS madness!

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...
  • Comment on Re: Re: Unorthodox Embedding/XS madness!