Correctly pass watcher to another loop
Marc Lehmann
schmorp at schmorp.de
Sun Jun 24 02:55:17 CEST 2012
On Sat, Jun 23, 2012 at 05:26:54PM +0400, Vladimir Afinello <vovan.af at gmail.com> wrote:
> In the current loop/thread I perform
> watcher.stop();
> ev_unref(thread1_loop_pointer);
Do you also have a corresponding ev_ref? (and is there a reaosn you would
need explciit ref/unref calls?).
> 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:
It's hard to believe that your program actually does what you describe,
and here is why: the assertion is inside ev_io_stop, which is called by
by start only when the watcher is still active. That contradicts the
watcher.stop earlier.
> What is the correct way to pass the watcher from one thread/loop to another
> thread/loop?
The above would be correct, without the ev_unref (and shouldn't cause that
problem even with the ev_unref), so best check your code to see what it
really does.
--
The choice of a Deliantra, the free code+content MORPG
-----==- _GNU_ http://www.deliantra.net
----==-- _ generation
---==---(_)__ __ ____ __ Marc Lehmann
--==---/ / _ \/ // /\ \/ / schmorp at schmorp.de
-=====/_/_//_/\_,_/ /_/\_\
More information about the libev
mailing list