Talk:cpp/thread/condition variable/wait until

"The clock tied to timeout_time is used, which means that adjustments of the clock are taken into account."

I was interested in how this is actually implemented for arbitrary clocks, so I've looked up the implementation of in libc++ and libstdc++. Both compute a duration from the absolute time point argument and the clock's. This duration is added to the current system clock's time. The resulting absolute time point is passed to. So there's no magic here that watches for clock adjustments. Unless they're somehow propagated into pthread (like adjustments of are, as far as I know), adjustments of arbitrary (user-defined) clocks are not taken into account into the time waited. Of course, once returns, the implementations look at how much time has actually passed, so the return value of  can reflect adjustments of any custom clock. Unfortunately, this computation is not (cannot?) be performed atomically with the exit from, so I think one can construct pathological cases where the return value doesn't accurately reflect clock adjustments as well. E.g. if the custom clock is set to an earlier time between the return of and the computation of the return value for, the return value might be , even though the absolute time point of the custom clock has expired.

"Thus, the maximum duration of the block might, but might not, be less or more [...]"

This sentence might, but might not, confuse me very much. IMO, the word "might" allows for the interpretation that it does not occur: "Thus, the maximum duration of the block might be less or more"

dyp --91.14.105.139 05:26, 2 July 2015 (PDT)


 * That paragraph was here since 2012, good find. POSIX spec is "For cases when the system clock is advanced discontinuously by an operator, it is expected that implementations process any timed wait expiring at an intervening time as if that time had actually occurred", but of course user-defined Clock means anything can happen. I think it would make sense to replace that paragraph with actual implementation details in a Notes section. --Cubbi (talk) 06:15, 2 July 2015 (PDT)
 * done --Cubbi (talk) 09:13, 14 July 2015 (PDT)

I think there are a mistake

Instead of: 2) Equivalent to while (!pred) {   if (wait_until(lock, abs_time) == std::cv_status::timeout) {        return pred;    } } return true; // <--- this is wrong.

Should be: 2) Equivalent to while (!pred) {   if (wait_until(lock, abs_time) == std::cv_status::timeout) {        return pred;    } } return false; // <-- should be false, not true.

— Preceding unsigned comment added by Maritimo (talk • contribs)
 * No, it is correct as written. The only way it can reach that return is if evaluated to true. T. Canens (talk) 02:29, 17 June 2018 (PDT)