Browse Source

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.
Jelle Raaijmakers 4 years ago
parent
commit
d1f33ec795
1 changed files with 1 additions and 1 deletions
  1. 1 1
      Userland/Libraries/LibPthread/pthread.cpp

+ 1 - 1
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;