Skip to content

Commit 236cb21

Browse files
Make CLOCK_MONOTONIC handling more precise in pal_threading.c (#50498)
The root cause of the problem in #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>
1 parent b46ffbf commit 236cb21

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/libraries/Native/Unix/System.Native/pal_threading.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ int32_t SystemNative_LowLevelMonitor_TimedWait(LowLevelMonitor *monitor, int32_t
173173

174174
error = pthread_cond_timedwait_relative_np(&monitor->Condition, &monitor->Mutex, &timeoutTimeSpec);
175175
#else
176-
#if HAVE_CLOCK_MONOTONIC
176+
#if HAVE_PTHREAD_CONDATTR_SETCLOCK && HAVE_CLOCK_MONOTONIC
177177
error = clock_gettime(CLOCK_MONOTONIC, &timeoutTimeSpec);
178178
assert(error == 0);
179179
#else

0 commit comments

Comments
 (0)