Using libev in a GUI

Marc Lehmann schmorp at schmorp.de
Wed Jan 6 07:40:40 CET 2010


On Tue, Jan 05, 2010 at 04:27:33PM -0800, John Wright <johnw at adobe.com> wrote:
> I need to embed a very simple server in a Mac carbon bundle that will be loaded when a GUI starts up.  It can't hang the main thread as the GUI needs to start responding to user interaction.  So I can't start an ev_loop in the main thread.  Are there any examples of people starting the ev_loop in another thread in this sort of situation?  I am not an experienced C programmer and was just hoping to build a simple webserver that will serve up one file.

There is nothing to worry about - starting it in another thread is working
exactly the same as starting it in the main thread.

The only thing you have to watch out for is that you can only
start/modify/stop watchers from that thread, not from the main thread.

You can use a pipe/socketpair or ev_async watchers to wake up your other
thread and tell him (e.g. by using a queue) to add/stop etc. watchers, but
that is indeed rather complicated.

Or in other words, running a separate libev thread is trivial,
communicating between threads is not (but maybe os x has some utilities
for that?).

-- 
                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