On 08.05.2012 16:54, Marc Lehmann wrote:
That's the standard idea, yes.

Good. I can block thread by running ev_run() in every thread.
Is there any pattern to block thread (and do something after the event is triggered) with one global loop (+synchronization of course)?

I don't quite understand that question, but you can judge yourself: in the current release of libev, if ev_run is blocking in a syscall, then ev_async_send will write a byte into a pipe (or use eventfd) to wake it up, once at most, per iteration. if the other thread is busy it merely
sets a global variable that is checked before ev_run blocks.

Sorry, I should have written ev_run().
Threads can block on mutexes/conditions/whatever and we can assume they don't use do any spinlockc and don't use any resources, right? If I run ev_run() in a thread and basically wait for async call can I assume it is also in a blocked state and doesn't 'eat' my CPU? ;-)

Plus, I would like to run some modules periodically, hence running
ev_timer or ev_periodic in a thread's loop.

Sounds fine to me.

Great.

One more thing. If Thread_1 send a ev_async_send() on Thread_2 loop/watcher and the callback will be called from within the Thread_2, right?

Plus, do you see any obstacles in implementing such a solution in C++ and with C++ wrappers?

--
regards,

Marek Denis
[[email protected]]

_______________________________________________
libev mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev

Reply via email to