在协作事件循环中要等待多少 epoll 事件?

问题描述

tl;dr: 考虑 epoll_wait:

int epoll_wait(int epfd,struct epoll_event *events,int maxevents,int timeout);

如何猜测或设置 maxevents

我正在构建一个不公开的协作事件循环 延续(又名回调)和过程是 not colored。这要归功于 call/cc

我不知道如何配置 epoll_waitmaxevents

以下是事件循环的功能

  • 事件循环运行可能在事件循环开始之前或事件循环运行期间产生的协程。
  • 一个协程可以在不阻塞其他协程的情况下休眠,
  • 一个 POSIX 线程可以在事件循环中生成协程。

这里是事件循环要点的伪代码

while loop.has_work?:
    # Resume all coroutines that have be spawned
    for coroutine in loop.coroutines-waiting:
        resume(coroutine)
    # Resume all coroutines that are sleeping
    for coroutine in loop.coroutines-to-wake-up:
        resume(coroutine)
    # Wait for MAXEVENTS
    for event in epoll.wait(...,MAXEVENTS,...):
        coroutine = loop.coroutine_waiting_for_event[event]
        resume(coroutine)

问题是:如何确定MAXEVENTSMAXEVENTS 是否应该等于使用 epoll_ctl 注册的事件总数?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)