Correctly pass watcher to another loop

Vladimir Afinello vovan.af at gmail.com
Sat Jun 23 15:26:54 CEST 2012


Greetings,

I have several threads in my program, each running an event loop.
After some period of time I need to pass one client (socket fd) from one
loop to another (and stop monitoring it in the current loop)

In the current loop/thread I perform
watcher.stop();
ev_unref(thread1_loop_pointer);
then pass the client data to second thread (using some kind of blocking
fifo) and then wake the secon thread using ev_async watcher
In second thread I perform:
pClientData->watcher.set(thread2_loop_pointer);
pClientData->watcher.set<&client_class::static_callback_fn>(pClientData);
pClientData->watcher.start(pClientData->fd, ev::READ);

sometimes it works, but in general the program breaks on
watcher.start(pClientData->fd, ev::READ) with:
ev.c:3250: ev_io_stop: Assertion ("libev: ev_io_stop called with illegal fd
(must stay constant after start!), w->fd >= 0 && w->fd <= ((loop)->anfdmax)
failed)

Howether I still can see in the debugger, that the fd is a valid int.

What is the correct way to pass the watcher from one thread/loop to another
thread/loop?
(I use Linux x86 with epoll backend)

Best regards, Vladimir
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/libev/attachments/20120623/98843cfe/attachment.html>


More information about the libev mailing list