Nick Ing-Simmons wrote:
Jeremy Redburn <[EMAIL PROTECTED]> writes:

Hello, I have some code which maintains a pool of Perl interpreters in C and allocates an interpreter as requests come in. It works well enough, but I have run into an issue that my embedded Perl code cannot print to STDOUT or STDERR.


What happens - what does $! show?

I have this statement in my code:

print STDERR "Testing" || print LOG "Error: $!"

Nothing gets printed to the terminal, and LOG doesn't have any content. I can print to LOG fine if I do it directly.

I am switching contexts between interpreters fairly often, and using PERL_NO_GET_CONTEXT and dTHX to set up the environment.


Ok so far, but passing interpreter pointer explicitly about is more efficent than dTHX.

I'll try switching to passing it around explicitly, but am more concerned with learning how Perl deals with tieing STDOUT and STDERR and how that may be messed up with my having multiple simultaneous Perl interpreters running.



Is it correct that dTHX will set up the environment for whichever Perl context is currently active?


Depends what you mean bet "currently active".
dTHX gets the pointer to the perl data structures from thread-local-storage.
So it gets _the_ interpreter struct for current thread.
If you are doing something more complex than one perl context per thread you need to do something more subtle.

I have a pool of Perl interpreters from which I select one that is not in use whenever a request comes in. I then switch to its context using PERL_SET_CONTEXT, then I use dTHX and make my API calls.



In any event, as the above probably makes clear, I have no idea what is causing the issue. I am working through it, but if this rings a bell for anyone I would appreciate any advice greatly.

Thanks,
Jeremy



Any help is, once again, greatly appreciated.

Reply via email to