Using ev_async for communication in the same event loop
Arun Athrey Chandrasekaran
achandr8 at ncsu.edu
Sun Apr 18 22:09:03 CEST 2021
I have a query regarding ev_async. I have a program running in an
event loop and that program cannot be blocked (i.e, sleep() or pthread_join
cannot be used). Now this program creates a thread to perform an action and
I have to wait for that thread to complete in a non-blocking manner. If the
thread does not complete within a specific time, the parent program has to
cancel the thread and move on. pthread_timedjoin_np() is one option for
this but it still blocks the parent program until the timeout happens.
I am using an ev_async watcher prior to creating the thread and inside the
thread routine, when the thread is done, I use ev_async_send on the same
loop as the parent program to let the parent program know that the thread
has finished. This way, the parent can create the thread and get notified
in an asynchronous way and not miss other events in the main event loop. Is
this expected to work? I looked at the documentation and it is not clear to
me if ev_async can be used for communication in the same event loop.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the libev