Behaviour Condvar::wait_timeout_while with 0 timeout

Is it reasonable to expect Condvar::wait_timeout_while to call condition callback at least once? Implementation at the time of this writing suggests that it is. Maybe it would be sensible to specify this behaviour?

The documentation specifies that

The returned WaitTimeoutResult value indicates if the timeout is known to have elapsed without the condition being met.

Which I’d understand to mean that the conditon has to be checked at the point of timing out, as otherwise it couldn’t correctly indicate whether “the timeout is known to have elapsed without the condition being met”.

Nonetheless, I see potential for documentation improvement. In particular the documentation of WaitTimeoutResult itself doesn’t clarify that the fn timed_out(&self) -> bool (uhh… a &self method on a Copy type, who wrote that… :roll_eyes:[1]) method indicates not simply timeout, but timeout without the condition being met. Ah wait… it’s the same type for Condvar::wait_timeout_while and for Condvar::wait_timeout, though the result type only claims the latter

It is returned by the wait_timeout method.

Even more documentation improvements… though then, for wait_timeout, the documentation of WaitTimeoutResult::timed_out is accurate.

  1. methods on such types (small Copy types) are typically fn (self), not fn(&self) ↩︎

I should clarify one detail. The case I have in mind is then the timeout is 0. I would like a guarantee that the wait_timeout_while will check the condition once, even if the timeout is 0. It seems to be the case right now. Do we want to clarify that it will still check the condition to prevent a possible implementation that will return immediately if the given timeout is 0?

The C++ standard seems to guarantee that, however, somewhat implicitly, by providing a "reference" code to which behaviour an implementation should adhere (as I understand it).

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.