How do I cancel a timer?

Graham Leggett minfrin at sharp.fm
Mon Dec 15 17:34:10 CET 2008


Hi all,

I have been trying to track down a problem in my code where a timer is 
being triggered after a call to:

	ev_timer_stop(msg->c->s->e->loop, &msg->timer.timer);

The ev_timer_stop is being called when the timer is being cleaned up, 
however the timer is somehow remaining active, and gets called again a 
little bit later, causing a crash as the underlying structure msg has 
been freed.

I have noticed that at the point at which ev_timer_stop is run, the 
active counter is reset to zero, and the timer structure looks like this:

44		ev_timer_stop(msg->c->s->e->loop, &msg->timer.timer);
(gdb)
46		if (msg->c) {
(gdb) print msg->timer
$20 = {
   timer = {
     active = 0,
     pending = 0,
     priority = 0,
     data = 0x0,
     cb = 0x4e09 <watch_timed_message_cb>,
     at = 3.9975130558013916,
     repeat = 2
   },
   msg = 0x81a458
}

Further on, when the crash occurs, the active counter has jumped back up 
to 3, and this timer has somehow become active again as follows:

(gdb) print w->msg->timer
$24 = {
   timer = {
     active = 3,
     pending = 0,
     priority = 0,
     data = 0x0,
     cb = 0x4e09 <watch_timed_message_cb>,
     at = 1229358265.3815961,
     repeat = 2
   },
   msg = 0x81a458
}

Can someone confirm first of all for me that ev_timer_stop is the 
correct way to cancel a timer?

The docs make no mention of how you destroy a timer, only how you might 
create one or reset one.

Regards,
Graham
--
-------------- 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: <http://lists.schmorp.de/pipermail/libev/attachments/20081215/4df2bb2c/attachment.bin>


More information about the libev mailing list