Event-loop libraries like libevent, maintain the timers in a min-heap and pass the timeout till the next timer expiry to select
/epoll
. Note that adding and removing a timer does not involve any system calls in this scenario, it just adds a new element into the min-heap.
When you use timerfd
, it takes 3 system calls (timerfd_create()
, timerfd_settime()
and epoll_ctl()
) just to create a timer. And every time it expires you need to read()
from that file descriptor.
timerfd
could be useful for applications without an event loop, but for ones that already use a decent event loop it is pretty much useless.