4 ms·
> This behavior is explicitly described in posix Where? Here's the [POSIX specification of poll][1], for reference. Nowhere in there can I find that it explici
by deathanatos 10y ago
> This behavior is explicitly described in posix
Where? Here's the [POSIX specification of poll][1], for reference. Nowhere in there can I find that it explicitly specifies the behavior of an empty-set poll. The only really relevant paragraph, with relation to the timeout arg is this one:
> If none of the defined events have occurred on any selected file descriptor, poll() shall wait at least timeout milliseconds for an event to occur on any of the selected file descriptors. If the value of timeout is 0, poll() shall return immediately. If the value of timeout is -1, poll() shall block until a requested event occurs or until the call is interrupted.
But "if none of the defined events have occurred" isn't really evaluable when there aren't any defined events in the first place; the answer is undefined because the question is wrong. Thus, it seems to me that this behavior is undefined, as far as POSIX is concerned.
(I wonder if this could be rephrased as, if ∃ fd∈∅ where none of the defined events have occurred on fd, then poll shall wait timeout…; this if is false (not undefined), so is should not wait the timeout. But then, the standard leaves us wondering what it should do, if not that. I think this reinterpretation depends on equating "any" with "at least one", though.)
(Having poll wait the timeout when passed the empty set certainly seems useful, but whether or not that's standard is a different question.)
[1]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html http://pubs.opengroup.org/onlinepubs/9699919799/functions/po...
- lmm 10y ago> "if none of the defined events have occurred" isn't really evaluable when there aren't any defined events in the first place It absolutely is evaluable. If there are no defined events then none of them has occurred. There's nothing weird or undefined about that; the empty set is empty.
- eridius 10y agoI don't think it's evaluable. > If none of the defined events have occurred on any selected file descriptor Note the "on any selected file descriptor". If there aren't any selected file descriptors to begin with, then the question doesn't even make sense. I can see how you could read it as saying it should sleep, but strictly speaking it seems like this is undefined behavior.
- lmm 10y agoThe question absolutely makes sense. There are no selected file descriptors. Trivially that means no event has occurred on any selected file descriptor. There is nothing undefined here.
- eridius 10y agoYou're taking one particular interpretation and treating that as the absolute truth. It's not. You've got a liberal interpretation, and a strict interpretation leaves it undefined. Just because you don't think it should be interpreted strictly doesn't mean the strict interpretation isn't a valid way to read it.
- lmm 10y agoNo, it really doesn't. That's what the world "any" means. There is no possible valid other way to read it. It's like saying "2 plus 2 is undefined, because if you interpret plus in a strict way the question is undefined".
- eridius 10y agoIf it was written "If there does not exist any selected file descriptor where a defined event has occurred", then I'd agree with you. But the way it's actually written presupposes that there are selected file descriptors.
- lmm 10y ago> But the way it's actually written presupposes that there are selected file descriptors. How so? It just says "If none of the defined events have occurred on any selected file descriptor, poll() shall wait at least timeout milliseconds for an event to occur on any of the selected file descriptors." "Any selected file descriptor" and "any of the selected file descriptors" make perfect sense for an empty array; nothing written there requires or implies any need for the array to be non-empty.
- duaneb 10y ago> If there are no defined events then none of them has occurred. No no, all (certainly any!) of them occurred.
- lmm 10y agoAll, but not any, and in fact none.
- Matthias247 10y agoYeah, it seems a little bit like arguing whether 0/0 is 0 or infinity without exact specification. While I would agree that the specification the poll case would favors sleeping I would still guess that it's pretty much undefined behavior as it's not a normal use-case to wait for nothing and would not rely on it. I don't see why a pure sleep behavior of poll would be wanted anyway, as it makes the eventloop unresponsive until the next timeout - which is normally not wanted in an eventdriven application. Normally I would always have at least one filedescriptor for eventloop wakeup (eventfd, signalfd, self-pipe, ...) in the poll set.
- JdeBP 10y agoWhen using ppoll() one can validly be waiting for (temporarily unmasked) signals alone.
- gpderetta 10y agoA pure sleep is exactly desirable when poll is coupled to a userspace timer queue. In this case you want to block until the next timer expires or the next io event, whatever come first. It is a fundamental building block of many event based applications.
- Matthias247 10y agoThat's totally right, forgot about that one. Probably used timerfd too much in the past :)