On Sun, Jul 01, 2012 at 12:12:41PM +0800, debuguo <waterawo...@gmail.com> wrote:
> hello everyone,
> 1.*about ev_async. *I use only one ev_async as the signal. when something
> happens, call ev_async_send(loop, &watcher). before the ev_async_send, I
> add one ev_async_pending(&watcher) to see the status of the watcher.
> ev_async_pending returns a non-zero value, which means "the event has not
> yet been processed (or even noted) by the event loop" .

Note that ev_async_pending is not documented to be call-able from another
thread than the one that runs the event loop, so you shouldn't call it to
see anything, because it does not do any kind of synchronisation.

> I'm afraid there's something missing. is it a solution to fix it?

Yeah, there's something missing: a description of the problem that you
perceive that needs a solution, because so far, you haven't mentioned
anything that needs a solution :)

> 2.*about shared ev_loop*. last time we were talking about the ev_run and
> ev_break in different thread need some mutex because the shared ev_loop.
> how about the ev_TYPE_stop, ev_TYPE_start? If I should add a mutex for them?

Everytime you access a shared resource from multiple threads you need a
mutex (or another form of synchronisation), so yes, you need a mutex there
too.

Literally the only call which is documented to be safe to call from
another thread is ev_async_send.

> 3. *about watchers in the ev_loop*. It seems that I should call
> ev_TYPE_stop to stop every watchers before ev_break or ev_loop_destroy.

There is no such requirement actually. It makes no sense for ev_break,
and is of limited use for ev_loop_destroy. When a loop gets destroyed,
it forgets about all watchers registered with it. Some watchers such as
signal watchers should be stopped though, as they also affect the process
state in other ways.

> Is there a API to get all the watchers?

No - libev doesn't internally keep track of all watchers.

> 4. *about exit ev_loop immediately*. How to use the setjmp or longjmp to
> exit ev_loop immediately?

I frankly think you shouldn't even consider setjmp/longjmp for loop exit
unless you already know quite well how to do it, but basically, youc all
setjmp before ev_run, and in a watcher callback, you longjmp.

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

_______________________________________________
libev mailing list
libev@lists.schmorp.de
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev

Reply via email to