diff options
author | github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | 2021-04-01 18:08:13 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-01 18:08:13 +0300 |
commit | 236cb21e3c1992c8cee6935ce67e2125ac4687e8 (patch) | |
tree | b0f7de8ea8193281077913c9a2401409fe44caa4 | |
parent | b46ffbf95ad809993a4cb5599655c309a673b89a (diff) |
Make CLOCK_MONOTONIC handling more precise in pal_threading.c (#50498)v6.0.0-preview.3.21201.4
The root cause of the problem in https://github.com/dotnet/runtime/pull/50388 turned out to be because we do not have `pthread_condattr_setclock(..., CLOCK_MONOTONIC);` on iOS.
This caused the timeout argument for `pthread_cond_timedwait` to be interpreted as an _absolute system time_ (in seconds since the Unix epoch), however the value we got back from `clock_gettime(CLOCK_MONOTONIC, ...)` was actually some value based on the uptime of the system.
Since the uptime is much smaller than the system time the wait immediately returned.
Harden the handling by adding a check for `HAVE_PTHREAD_CONDATTR_SETCLOCK` like we already do in `SystemNative_LowLevelMonitor_Create()`
Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
-rw-r--r-- | src/libraries/Native/Unix/System.Native/pal_threading.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/libraries/Native/Unix/System.Native/pal_threading.c b/src/libraries/Native/Unix/System.Native/pal_threading.c index cf739c84542..6f69d1056b8 100644 --- a/src/libraries/Native/Unix/System.Native/pal_threading.c +++ b/src/libraries/Native/Unix/System.Native/pal_threading.c @@ -173,7 +173,7 @@ int32_t SystemNative_LowLevelMonitor_TimedWait(LowLevelMonitor *monitor, int32_t error = pthread_cond_timedwait_relative_np(&monitor->Condition, &monitor->Mutex, &timeoutTimeSpec); #else -#if HAVE_CLOCK_MONOTONIC +#if HAVE_PTHREAD_CONDATTR_SETCLOCK && HAVE_CLOCK_MONOTONIC error = clock_gettime(CLOCK_MONOTONIC, &timeoutTimeSpec); assert(error == 0); #else |