Dear Dave, Yes, the perl interpreters are not the same:
# perl thread (gdb) p my_perl $1 = (PerlInterpreter *) 0xb (...) dSP; (gdb) p my_perl $7 = (PerlInterpreter *) 0x555555953260 (...) # mpv thread: (gdb) p my_perl $2 = (PerlInterpreter *) 0x1 (...) dSP; (gdb) p my_perl $3 = (PerlInterpreter *) 0x0
Regarding the creation of the extra threads: To be honest, I don't know how they are created and what with the main perl thread happens. This is managed by libmpv and I don't know and understand the code very well.. The error seems to occur in mpv_initialize from mpv-player/client.c, which calls mp_wakeup_core from mpv-player/playloop.c that triggers an event from the saved dispatch queue. mpv/misc/dispatch.c describes it as follows: "A dispatch queue lets other threads run callbacks in a target thread. The target thread is the thread which calls mp_dispatch_queue_process()." This is here mp_dispatch_interrupt which was called in mp_wakeup_core. So I think the target thread is created in mpv_create with the following lines:
pthread_t thread; if (pthread_create(&thread, NULL, core_thread, mpctx) != 0) { ctx->clients->have_terminator = true; // avoid blocking mpv_terminate_destroy(ctx); mp_destroy(mpctx); return NULL; }
core_thread() consists of the following lines:
static void *core_thread(void *p) { struct MPContext *mpctx = p; mpthread_set_name("mpv core"); while (!mpctx->initialized && mpctx->stop_play != PT_QUIT) mp_idle(mpctx); if (mpctx->initialized) mp_play_files(mpctx); // This actually waits until all clients are gone before actually // destroying mpctx. Actual destruction is done by whatever destro +ys // the last mpv_handle. mp_shutdown_clients(mpctx); return NULL; }
I don't know whether this is helpful. Perhaps the task is a number too big for me because I have no clue regarding threads? Nevertheless thank you very much for all your help and patience..

Max

PS.: I also don't understand why one time the callback is called in the perl thread? Perhaps because of the following line in mpv_set_wakeup_callback?
if (ctx->wakeup_cb) ctx->wakeup_cb(ctx->wakeup_cb_ctx);

In reply to Re^3: XS callback to mpv_set_wakeup_callback by MaxPerl
in thread XS callback to mpv_set_wakeup_callback by MaxPerl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.