From d1f33ec795f3deddd3d8b313ceb11dbc22fb7541 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Mon, 26 Apr 2021 17:22:25 +0200 Subject: [PATCH] LibPthread: Use realtime clock for futex_wait() If we get an absolute time passed to one of the pthread_*wait methods, this is not an absolute monotonic time but rather an absolute wall time. This means that we also need to pass FUTEX_CLOCK_REALTIME to the futex syscall to ensure we're not using the monotonic clock. --- Userland/Libraries/LibPthread/pthread.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Libraries/LibPthread/pthread.cpp b/Userland/Libraries/LibPthread/pthread.cpp index 6e95517df3..d9fcb48627 100644 --- a/Userland/Libraries/LibPthread/pthread.cpp +++ b/Userland/Libraries/LibPthread/pthread.cpp @@ -442,7 +442,7 @@ static int futex_wait(uint32_t& futex_addr, uint32_t value, const struct timespe { int saved_errno = errno; // NOTE: FUTEX_WAIT takes a relative timeout, so use FUTEX_WAIT_BITSET instead! - int rc = futex(&futex_addr, FUTEX_WAIT_BITSET, value, abstime, nullptr, FUTEX_BITSET_MATCH_ANY); + int rc = futex(&futex_addr, FUTEX_WAIT_BITSET | FUTEX_CLOCK_REALTIME, value, abstime, nullptr, FUTEX_BITSET_MATCH_ANY); if (rc < 0 && errno == EAGAIN) { // If we didn't wait, that's not an error errno = saved_errno;