ev_async delays thread when joining

Marc Lehmann schmorp at schmorp.de
Sun Jan 2 03:47:30 CET 2011

On Sat, Jan 01, 2011 at 08:10:30PM -0400, Juan Pablo L <jpablolorenzetti at gmail.com> wrote:
> Hi, i m new to libev and i m trying to use ev_async to signal some threads
> for some events, everything is ok but when the threads end
> they take very long to be joined, like in minutes which makes the
> application not responsive (i need them to be joinable in the real
> application), i m sure the problem is with ev_async,
> i have tested without it and with it, the problem is the ev_async but i have
> no idea where the problem is, doing strace it shows that the loop gets stack
> at epoll in a futex call,

libev doesn't do any futex calls, so if it gets stuck in one, it means it'S
in somebody elses code.

> void *the_thread_function(struct ev_loop *evt_loop)
> {
>         ev_run(evt_loop,0);
>         pthread_exit(NULL);
> }

this is one thread.

>         while(--i >= 0)
>         {
>                 printf("i = %d\n",i);
>                 ev_async_send(evt_loop,&as_evt);
>                 sleep(1);
>         }
>         ev_break(evt_loop,EVBREAK_ALL);
>         printf("stopping watcher\n");
>         ev_async_stop(evt_loop,&as_evt);

and this is another. I don't see you locking the loop, so this is the first
thing you need to fix: the only call allowed on an event loop used in another
thread is ev_async_send, no other calls may be done.

if you want to join the thread, you could make the thread
cancelable/uncanceble via ev_set_loop_release_cb, and just cancel it.

or you could pthread_exit in the async watcher callback, and
ev_async_send, then join.

                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at schmorp.de
      -=====/_/_//_/\_,_/ /_/\_\

More information about the libev mailing list