Copying a watcher

Zsbán Ambrus ambrus at math.bme.hu
Wed Jan 5 21:24:36 CET 2011


On Wed, Jan 5, 2011 at 5:30 PM, Gabriel Kerneis <kerneis at pps.jussieu.fr> wrote:
> is it safe to copy a (potentially active or pending) watcher, destroy
> the original one and use only the copy afterwards?
>
> (Or maybe my question should be: does libev retain pointers to
> active/pending watchers?)
>
> I might have missed it but did not find anything about it in the manual.

I think it's not safe to do that.  For one, when ev calls your
callback, it passes a pointer to the watcher.  If that wasn't enough,
some watchers have structure members (eg. repeat in ev_timer) which
the documentation guarantees you can safely modify any time, even if
the watcher is active, so ev will definitely have to be able to access
the watcher structure.

I don't know whether it's safe to move a stopped watcher though.

Ambrus



More information about the libev mailing list