4 ms·
Maybe I am out of date. (I probably am because I haven't written any code that uses select() for two decades.) Can somebody please identify the POSIX method b
by anonymousiam 5y ago
Maybe I am out of date. (I probably am because I haven't written any code that uses select() for two decades.)
Can somebody please identify the POSIX method by which one can wait on a set of descriptors, that does not involve spinning in a polling loop and gobbling up a CPU thread? The last time I had a need for such a thing, select() was the preferred way to do that.
- DDR0 5y agoThe article mentions a few near the end, I think.
- masklinn 5y agoThe article mentions one (poll) and doesn’t make it clear they it’s posix. The rest is Linux specific. Aside from being a lot more recent (posix 2001), poll was also broken on macOS until 10.9. Though you can always use kqueue instead that remains a portability annoyance: Linux still doesn’t have kqueue.
- sgtnoodle 5y agoEpoll works really well in Linux.
- anonymousiam 5y agoI'm sure that epoll() works great, but I was asking about a POSIX replacement. Some people still write portable code.
- hyperman1 5y agoWhile this is a laudable goal and good for uncovering unexpected bugs, it also means writing for the lowest common baseline. And in this case, the lowest common baseline is unfortunately not very high. poll is what you want, but has its own gnarly gremlins. Better mechanisms are not standardized.
- slezyr 5y agoWhy not use libevent or libuv, and make it portable for all other platforms?
- cesarb 5y agoThe POSIX alternative to select() is poll(): https://man7.org/linux/man-pages/man2/poll.2.html#CONFORMING_TO https://man7.org/linux/man-pages/man2/poll.2.html#CONFORMING...
- throw0101a 5y agoSee also: * https://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html https://pubs.opengroup.org/onlinepubs/9699919799/functions/p...
- jabl 5y agoAs others mentioned, the POSIX alternative is poll() (and ppoll() as the alternative to pselect() ). If you want both portability and performance (as in, O(1) instead of O(N) as poll() and select() ), there's no portable standard. In that case you're better of with a wrapper library like libuv or livev.
- geocar 5y agopoll() is POSIX but slower than select()