How do I cancel a timer?

Graham Leggett minfrin at
Tue Dec 16 12:11:24 CET 2008

Marc Lehmann wrote:

> On Mon, Dec 15, 2008 at 06:34:10PM +0200, Graham Leggett <minfrin at> wrote:
>> Can someone confirm first of all for me that ev_timer_stop is the  
>> correct way to cancel a timer?
> Yes - are you sure you don't start it again, or modify it in illegal ways?

What I found I had done was initialised the timer twice. It seems that 
when this happens you have to stop the timer twice, or a single stop of 
the timer isn't effective.

>> The docs make no mention of how you destroy a timer, only how you might  
>> create one or reset one.
> Because destruction is on your side of the API - libev has no facilities
> to create or destroy timers, that's what the application does.
> The documentation mentions exactly, however, when you can safely reuse the
> watcher structure for something else, which is what you seem to want.
> But remember, creation and destruction _for watchers_ is completely
> outside the libev API, only _event loops_ can be created and destructed.

What I meant by "destroy a timer" is "make sure this callback is never 
executed, because the memory beneath this is about to be freed".

At the moment, I am using ev_timer_stop() for this, and as long as I 
don't initialise the same timer twice, it seems to work.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3287 bytes
Desc: S/MIME Cryptographic Signature
URL: <>

More information about the libev mailing list