Skip to content
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

Merged
merged 2 commits into from
Apr 11, 2016
Merged

std.concurrency: receiveTimeout: allow negative timeout #3545

merged 2 commits into from
Apr 11, 2016

Conversation

sigod
Copy link
Contributor

@sigod sigod commented Aug 10, 2015

Related #3516.

This assert was introduced in #1910, which contradicts #1279.

@DmitryOlshansky
Copy link
Member

LGTm

@WalterBright
Copy link
Member

Rationale?

@sigod
Copy link
Contributor Author

sigod commented Aug 15, 2015

@complexmath, you might like to take a look at this.

@complexmath
Copy link
Member

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.

@sigod
Copy link
Contributor Author

sigod commented Aug 25, 2015

A negative timeout doesn't really make sense.

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?

@schveiguy
Copy link
Member

Or alternately, considering any negative timeout equivalent to zero if we want to be forgiving of bad math

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.

@complexmath
Copy link
Member

@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.

@complexmath
Copy link
Member

@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.

@DmitryOlshansky
Copy link
Member

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?

Seems like both should 'yield' current thread/fiber. @sigod up to the task?

@sigod
Copy link
Contributor Author

sigod commented Nov 10, 2015

@DmitryOlshansky Sorry for long response.

Seems like both should 'yield' current thread/fiber.

You mean that both, zero and negative timeouts, should "yield"?

Like this?

if( period <= Duration.zero || !m_putMsg.wait( period ) )
    return false;

@DmitryOlshansky
Copy link
Member

You mean that both, zero and negative timeouts, should "yield"?

Like this?

Yes - that would check mailbox and yeild if empty.

@sigod
Copy link
Contributor Author

sigod commented Dec 9, 2015

Done.

@sigod
Copy link
Contributor Author

sigod commented Feb 9, 2016

@DmitryOlshansky, ping.

@DmitryOlshansky
Copy link
Member

Auto-merge toggled on

@DmitryOlshansky
Copy link
Member

@sigod Sorry forgot about this one

@DmitryOlshansky DmitryOlshansky merged commit 7988eae into dlang:master Apr 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants