Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

xs wrapper for a threaded library

by fng (Sexton)
on Sep 30, 2015 at 20:32 UTC ( [id://1143467]=perlquestion: print w/replies, xml ) Need Help??

fng has asked for the wisdom of the Perl Monks concerning the following question:

I am writing an XS wrapper to a library that makes its own threads and also expects C style callbacks. The intent is to use this library in a perl application, not in a C application with embedded perl. My design hinges on being able to call a perl sub within the C-style callback, allowing this library to throw events at me and for me to handle these events in perl. The problem is that the library in question is multi-threaded, and I never know what thread it will be executing in when it calls the C-style callback. From there I cannot call any perl API functions because I have no interpreter context. I realize that this is because perl is meant to start the threads so it can clone the interpreter at that point; because the library manages its own threads I end up unable to look up an interpreter.

So, my question is, what should I do? I can try to start a perl interpreter within the callback, but I have none to clone and I am nervous about managing the collection of cloned interpreters myself. I could try to handle the callback by passing info about the events back to one of the perl-capable threads in some pure-C based manner (zmq, is my first guess). I'm not sure if there is a better option, any suggestions or advice would be appreciated.

Replies are listed 'Best First'.
Re: xs wrapper for a threaded library
by BrowserUk (Patriarch) on Sep 30, 2015 at 21:35 UTC
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1143467]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-03-28 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found