Threaded Example clarification

Anthony Clark clark.anthony.g at gmail.com
Thu Nov 13 23:34:16 CET 2014


Hey all,

First off. Thanks for libev - it's great. I've having issues understand the
fundamentals of allowing loops to be modified via other threads. I've
skimmed most of the mailing list and couldn't find a solution to this. I
think my confusion comes from the documentation, where it states:

"""
Instead of invoking all pending watchers, the l_invoke callback will signal
the main thread via some unspecified mechanism (signals? pipe writes?
Async::Interrupt?)

"""
    1  static void
    2    l_invoke (EV_P)
    3    {
    4      userdata *u = ev_userdata (EV_A);
    5
    6      while (ev_pending_count (EV_A))
    7        {
    8          wake_up_other_thread_in_some_magic_or_not_so_magic_way ();
    9          pthread_cond_wait (&u->invoke_cv, &u->lock);
   10        }
   11    }


I tried going through the perl module but I never saw what `sig_func` or
`sig_arg` were. Maybe if I knew those, I'd get a hint. Since the loop (in
the Thread Locking example) is processes solely in a separate (from main)
thread, what could/would the main thread need to know about? Maybe cleaning
up my other confusion below might answer this.

It doesn't appear that `real_invoke_pending` is never actually invoked in
the Thread Locking example. In the perl module, it's handled by the module
system (c_func) and I can't really figure it out where in the flow it's
actually invoked.

    1    static void
    2    real_invoke_pending (EV_P)
    3    {
    4      userdata *u = ev_userdata (EV_A);
    5
    6      pthread_mutex_lock (&u->lock);
    7      ev_invoke_pending (EV_A);
    8      pthread_cond_signal (&u->invoke_cv);
    9      pthread_mutex_unlock (&u->lock);
   10    }

So to narrow it down. I understand the acquire/release callbacks, I
understand locking `ev_run`. I guess I just don't understand the flow of
the invoke_pending callback. Any help is appreciated! Also, sorry for the
newbie questions.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/libev/attachments/20141113/910b2bf0/attachment.html>


More information about the libev mailing list