Marc Lehmann wrote:
On Tue, Jan 05, 2010 at 04:27:33PM -0800, John Wright <[email protected]> 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.
Actually, I have code that starts and stops watchers on the event loop
associated with thread A, from thread B. I use ev_asyncs to poke thread
A to let him know that watcher state was changed. This seems to work.
Is it not designed to work? There would be no problem in moving the
calls to change watcher state over to be inside the async callback, but
then I'd have to either create one async callback per watcher or attach
state to one of the passed in data structures.
_______________________________________________
libev mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev