-
-
Notifications
You must be signed in to change notification settings - Fork 700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std.concurrency: receiveTimeout: allow negative timeout #3545
Conversation
LGTm |
Rationale? |
@complexmath, you might like to take a look at this. |
A negative timeout doesn't really make sense. I'd vote in favor of requiring a non-negative timeout. Or alternately, considering any negative timeout equivalent to zero if we want to be forgiving of bad math. As long as it's consistent, either is acceptable, though rejecting negative values makes a bit more sense to me. |
Indeed it doesn't. But I hoped to hear some details of why you worked with negative timeout originally. I agree with requiring a non-negative timeout. But let's make zero timeout a true no wait. As it's currently with negative values: if( period.isNegative || !m_putMsg.wait( period ) )
return false; Shall I create new PR? |
I think this is the best option. Timing on a non-realtime OS is never exact, and if you are running a calculation of how long to wait for something, it's quite easy to get into this situation. For example if you want to check for messages while running a callback every 100ms, it's quite possible your callback may take longer than 100ms (or you get swapped out by the OS), and then your next wait time will be negative. To push that check onto the user seems counter-productive. |
@sigod No. The current behavior for a timeout of zero is equivalent to a yield(), which I think is important if the underlying scheduler incorporates fibers. |
@schveiguy That was the case I considered as well. It seems like it could be easy to wind up with a negative timeout if you're decaying the value or something. If I were writing the user code I'd check, but I think it's fair to state that the API will handle these values gracefully instead of asserting. |
Seems like both should 'yield' current thread/fiber. @sigod up to the task? |
@DmitryOlshansky Sorry for long response.
You mean that both, zero and negative timeouts, should "yield"? Like this? if( period <= Duration.zero || !m_putMsg.wait( period ) )
return false; |
Yes - that would check mailbox and yeild if empty. |
Done. |
@DmitryOlshansky, ping. |
Auto-merge toggled on |
@sigod Sorry forgot about this one |
Related #3516.
This assert was introduced in #1910, which contradicts #1279.