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

Re: XS callback to mpv_set_wakeup_callback

by dave_the_m (Monsignor)
on Jan 04, 2019 at 16:59 UTC ( [id://1228037]=note: print w/replies, xml ) Need Help??


in reply to XS callback to mpv_set_wakeup_callback

I suspect your problem lies in some random foreign thread calling the callback. The dTHX macro in your callback function expands (depending on platform and configuration) to something like
PerlInterpreter* my_perl = pthread_getspecific(PL_thr_key);
This means that it attempts to set the current interpreter (my_perl) to whatever value is stored in thread-local storage for that thread. For a perl thread, that value will point to the interpreter associated with that thread. For a foreign thread, it's likely to be NULL.

The question is, if a foreign thread calls the callback, what interpreter structure should it use? Once you have decided that, then you'll need to do

PERL_SET_CONTEXT(some_perl);
at some point. See perlguts and perlembed.

The question of what interpreter to use depends on your setup - how threads are created and managed - but in any case, you need to avoid two separate threads sharing the same interpreter.

Dave.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2024-04-23 17:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found