ev_timer problem

Marc Lehmann schmorp at schmorp.de
Wed Jul 9 10:42:25 CEST 2008


On Mon, Jul 07, 2008 at 03:54:21PM +0300, vvvua <vvvua at faust.net.ua> wrote:
> When ev_loop finishes to maintain all registered timers, it waits on  
> epoll, and epoll waits for events from sockets.
> When i register a new timer in the second thread, ev_loop still waits on  
> epoll...

Of course, this is not allowed.

> To resolve this problem i created a heartbeat timer in the main thread.

It's not a solution, your program will just crash at different times now.

Get a book about threads programming and elarn about race conditions, and how
to avoid them (e.g. by using a mutex). Also refer to the threads section in
the libev manual. In short, if you don't lock the loop yourself, then the only
thing you can do in another thread is to call ev_async_send.

> Another solution - is to set timeout on sockets read/write operations.

Not sure what that solves, but you need to understand thread programming
and use proper locking to avoid races, otherwise your program runs into
undefined behaviour (most likely, crashes).

This is all documented in the libev documentation, however.

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



More information about the libev mailing list