[libc-commits] [libc] [libc] clean up futex usage (PR #91163)

Schrodinger ZHU Yifan via libc-commits libc-commits at lists.llvm.org
Mon May 6 08:06:46 PDT 2024


SchrodingerZhu wrote:

@nickdesaulniers I see both bionic and rust's std library uses only `CLOCK_MONOTONIC` even though `CLOCK_REALTIME` is suggested by POSIX. See below comments from bionic:
```c++
  // pthread's and semaphore's default behavior is to use CLOCK_REALTIME, however this behavior is
  // essentially never intended, as that clock is prone to change discontinuously.
  //
  // What users really intend is to use CLOCK_MONOTONIC, however only pthread_cond_timedwait()
  // provides this as an option and even there, a large amount of existing code does not opt into
  // CLOCK_MONOTONIC.
  //
  // We have seen numerous bugs directly attributable to this difference.  Therefore, we provide
  // this general workaround to always use CLOCK_MONOTONIC for waiting, regardless of what the input
  // timespec is.
  ```

Should we also do something similar? (i.e. not expose realtime clock and document that one should always translate realtime lock to monotonic clock)

https://github.com/llvm/llvm-project/pull/91163


More information about the libc-commits mailing list