5 ms·
Yes. The timeout is specified, but no file descriptors is given. (so calling poll() behaves like sleep/usleep ). This behavior is explicitly described in posix
by noselasd 10y ago
Yes. The timeout is specified, but no file descriptors is given. (so calling poll() behaves like sleep/usleep ).
This behavior is explicitly described in posix, worked prior to OSX 10.12, but behaves differently as of OSX10.12
- mikepurvis 10y agoIsn't the distinction that poll/select will only block only the current thread, whereas sleep may block the whole process?
- to3m 10y agosleep blocks the calling thread: http://pubs.opengroup.org/onlinepubs/009695399/functions/sleep.html http://pubs.opengroup.org/onlinepubs/009695399/functions/sle...
- 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".