From fb852fd3e712ef26cf67a5b4ee4e85b7eb4affba Mon Sep 17 00:00:00 2001 From: Doron Somech Date: Sun, 28 Jun 2020 17:02:38 +0300 Subject: [PATCH] problem: pthread_cond_timedwait sometimes fail with EINVAL Solution: fix rounding error and assert if the clock_gettime fails --- src/condition_variable.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/condition_variable.hpp b/src/condition_variable.hpp index 66412d37..47d14e79 100644 --- a/src/condition_variable.hpp +++ b/src/condition_variable.hpp @@ -259,13 +259,14 @@ class condition_variable_t timeout.tv_sec = 0; timeout.tv_nsec = 0; #else - clock_gettime (CLOCK_MONOTONIC, &timeout); + rc = clock_gettime (CLOCK_MONOTONIC, &timeout); + posix_assert (rc); #endif timeout.tv_sec += timeout_ / 1000; timeout.tv_nsec += (timeout_ % 1000) * 1000000; - if (timeout.tv_nsec > 1000000000) { + if (timeout.tv_nsec >= 1000000000) { timeout.tv_sec++; timeout.tv_nsec -= 1000000000; }