为什么不在 linux(timerfd) 上使用系统定时器?

kua*_*ngi 3 c++ linux timer

我发现大部分服务器(例如RPG网页游戏服务器)总是自己实现定时器而不是使用系统定时器,例如在linux上,

int timerfd_create(int clockid, int flags)
Run Code Online (Sandbox Code Playgroud)

你能告诉我为什么吗?我认为系统 api(timerfd_create) 可以有更高的性能。

Bas*_*tch 5

阅读时间(7)。确实,timerfd_create(2)是有效的,但它是 Linux 特定的。

timer_create(2)人中使用 Posix 计时器。可能更便携。

Linux 特定的timerfd_create(以及signalfd(2)eventfd(2) ...)的显着优势是对事件循环友好(因为它是一个文件描述符,例如管道或套接字)。但是,大多数事件循环都建立在多路复用系统调用之上,例如poll(2)接受延迟(毫秒)或较旧的select(2)