Product SiteDocumentation Site

2.3. select/poll based state machines

The select(2)/poll(2) system calls allow one process to wait for events on multiple file descriptors. The distinctive point of this architecture is to never use a sleeping system call while handling a request, but to always return to the main loop, which is built around select(2) or poll(2). This architecture certainly resolves the issue of process creation overhead present in the Forking server architecture. However, the select/poll mechanism does not utilize concurrency at all. The code tends to be much harder to understand and to maintain, because the request processing falls apart into callbacks called from the main loop.
To overcome the code maintainability issue of this approach, one might use a user space threading library like GNU pth, or employ user land stack switching using makecontext(3) and swapcontext(3) or setjmp(3), longjmp(3) and sigaltstack(2). GNU pth actually uses the latter; a paper describing this approach in depth is available.