回复: Is it safe to call ev_feed_event on an ev_timer in different thread?

钱晓明 mailtoantares at 163.com
Mon Aug 27 15:55:21 CEST 2012


so, I should use an extra ev_async to call ev_feed_event for that ev_timer? This ev_async in the same thread, and call ev_feed_event in its callback. 

发送自HTC手机

----- Reply message -----
发件人: "Marc Lehmann" <schmorp at schmorp.de>
收件人: "钱晓明" <mailtoantares at 163.com>
抄送: "libev" <libev at lists.schmorp.de>
主题: Is it safe to call ev_feed_event on an ev_timer in different thread?
日期: 周一, 8 月 27 日, 2012 年 12:50


On Sun, Aug 26, 2012 at 09:55:42PM +0800, 钱晓明 <mailtoantares at 163.com> wrote:
> Hi, is ev_feed_event is thread safe?

As long as you call it on the same loop only in one thread at a time, yes.

> I have an ev_timer installed in a loop within main thread, can I call
> ev_feed_event in another thread to simulate the time out event?

Not without locking the event loop, e.g. with a mutex (you could use the
acquire/release callbacks and an ev_async watcher to lock/unlock and wake
up the loop).

> Is it safe?

Without proper locking, no, it will most likely corrupt libev's internal
data structures and not even work.

-- 
                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at schmorp.de
      -=====/_/_//_/\_,_/ /_/\_\
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/libev/attachments/20120827/776b5eda/attachment.html>


More information about the libev mailing list