How do I cancel a timer?

James Mansion james at
Fri Dec 19 21:44:07 CET 2008

Brandon Black wrote:
> The problem with an initialization flag byte is this then requires 
> that the memory being passed to the init function be zero-d (or at 
> least, the flag byte within it be zero-d),
Well, I'd question whether its a problem (certainly not from any performance
perspective) but since it busts the API its not relevant in this case, 
because the design decision to have the multiple-init bug undetectable is
effectively made.  I'm just objecting to Mr Lehman's characteristically
condescending and heavy-handed 'its not possible'.

> is basically going to fall into the same class of application 
> programming bug/mistake as the problem we're trying to avoid in the 
> first place).

I don't think that's true at all. An API that refuses to work unless the 
user has fullfilled
preconditions will tend to be overzealous rejecting calls, and will be 
more inconvenient,
but I do think it will tend to have fewer errors.  No API will be 
completely immune
after all, particularly if you are going to *try* to think of ways that 
it *could* be
subverted, rather than accept that the API lends itself to a reinit bug..

Personally I'd be hesitant about overoptimising in a library that is 
about calling select in one way or another, and would have thought that 
a simple object
pool would be adequate.  All that's happened is that we've shifted the 
somewhere else, and it will only actually be a saving if there's a 
relationship between timers and application entities.  All the 
timer-centric systems
I've worked with have had timers in the Controller in the overall MVC 
and held
them to one side, so I suspect it may not be all that much of a cost 
unless you go
for a really malloc-heavy approach with no pooling.

More information about the libev mailing list