From 30580ed7e44a242befff02ea8496de0735351861 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Wed, 24 Nov 2021 18:40:36 +0100 Subject: [PATCH] LibPthread: Initialize conditions with realtime clock All the way back in commit 1670ee5aba09, the default clock for condition variables was set to `CLOCK_MONOTONIC`, because there was no other clock available. However, if a condition variable is initialized without any additional attributes by an application, they sometimes assume that the absolute time that is passed to e.g. `pthread_cond_timedwait` is actually based on a realtime clock, as can be seen here in SDL2: https://github.com/SerenityPorts/SDL/blob/6f419bdf5f56be236c070a9d364e0d238b868565/src/thread/pthread/SDL_syscond.c#L99 Additionally, the glibc implementation defaults to a realtime clock: https://github.com/bminor/glibc/blob/aac54dcd378209bbdddbcec749561b1d8f167d11/nptl/pthread_cond_init.c#L42 ...so we probably should do so as well :^) --- Userland/Libraries/LibPthread/pthread_cond.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Libraries/LibPthread/pthread_cond.cpp b/Userland/Libraries/LibPthread/pthread_cond.cpp index 7913daec61..41f1c842a1 100644 --- a/Userland/Libraries/LibPthread/pthread_cond.cpp +++ b/Userland/Libraries/LibPthread/pthread_cond.cpp @@ -48,7 +48,7 @@ int pthread_cond_init(pthread_cond_t* cond, const pthread_condattr_t* attr) { cond->mutex = nullptr; cond->value = 0; - cond->clockid = attr ? attr->clockid : CLOCK_MONOTONIC_COARSE; + cond->clockid = attr ? attr->clockid : CLOCK_REALTIME_COARSE; return 0; }