Common optimization for timers with event loops
I discuss a common optimization with timer functionality in event loops implementations.
For a concrete example to reference in the above discussion have a look at kqueue which is part of FreeBSD (the core of Mac OS X):
int kevent(int kq, const struct kevent *changelist, int nchanges,
struct kevent *eventlist, int nevents,
const struct timespec *timeout);
Notice how it takes a timeout argument? The same is true for the Berkley sockets select call:
int select(int nfds, fd_set *restrict readfds,
fd_set *restrict writefds, fd_set *restrict exceptfds,
struct timeval *restrict timeout);
Different implementation with the same core underlying need. Make sense?