tl;dr: Considering
epoll_wait
:int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout);
How to guess or set
maxevents
?
I am building a cooperative event-loop that does not expose
continuations (aka. callbacks) and where procedures are not
colored. That can be achieved thanks to call/cc
.
I do not know how to configure epoll_wait
's maxevents
.
Here are the features of the event loop:
- The event loop runs coroutines that may be spawned before the event loop start or during the event loop is running.
- A coroutine can sleep without blocking other coroutines,
- Another POSIX thread can spawn a coroutine in an event-loop.
Here is the pseudo-code of the gist of the event-loop:
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)
The question is: how to determine MAXEVENTS
? Should MAXEVENTS
be equal to the total number of events registred with epoll_ctl
?