[PATCH 1/2] condition_variable: Report early wakeup of wait_until as no_timeout

François Dumont frs.dumont@gmail.com
Tue Jul 24 10:04:00 GMT 2018


On 20/07/2018 18:49, Mike Crowe wrote:
> As currently implemented, condition_variable always ultimately waits
> against std::chrono::system_clock. This clock can be changed in arbitrary
> ways by the user which may result in us waking up too early or too late
> when measured against the caller-supplied clock.
>
>          PR libstdc++/86595
> diff --git a/libstdc++-v3/include/std/condition_variable b/libstdc++-v3/include/std/condition_variable
> index 84863a1..a2d146a 100644
> --- a/libstdc++-v3/include/std/condition_variable
> +++ b/libstdc++-v3/include/std/condition_variable
> @@ -116,7 +116,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>          const auto __delta = __atime - __c_entry;
>          const auto __s_atime = __s_entry + __delta;
>
> -       return __wait_until_impl(__lock, __s_atime);
> +       // We might get a timeout when measured against __clock_t but
> +       // we need to check against the caller-supplied clock to tell
> +       // whether we should return a timeout.
> +       if (__wait_until_impl(__lock, __s_atime) == cv_status::timeout)
> +         return _Clock::now() < __atime ? cv_status::no_timeout : cv_status::timeout;
> +       else
> +         return cv_status::no_timeout;
>         }

This patch claims that it just replaces a cv_status::timeout into 
cv_status::no_timeout if we didn't wait enough. But it also replaces any 
cv_status returned by __wait_until_impl into a cv_status::no_timeout, is 
that intentional ? IMHO it should store the returned status and return 
it unchanged if not timeout.



More information about the Libstdc++ mailing list