pthread_cond_timedwait need use support CLOCK_MONOTONIC setting
- Dominant language
- C++
- Stars
- 32.1k
- Forks
- 6.9k
- Avg merge
- 32m
- Merged PRs (30d)
- 1
Description
> Note: Please use Issues only for bug reports. For questions, discussions, feature requests, etc. post to dev group: https://www.facebook.com/groups/rocksdb.dev
### Expected behavior
when we want to wait the timeout condition, if the system administrator manually changes the clock or System time jump。 In particular, the time hops forward , this thread will be halt for a long time。
bool CondVar::TimedWait(uint64_t abs_time_us) {
struct timespec ts;
ts.tv_sec = static_cast(abs_time_us / 1000000);
ts.tv_nsec = static_cast((abs_time_us % 1000000) * 1000);
#ifndef NDEBUG
mu_->locked_ = false;
#endif
int err = pthread_cond_timedwait(&cv_, &mu_->mu_, &ts);
#ifndef NDEBUG
mu_->locked_ = true;
#endif
if (err == ETIMEDOUT) {
return true;
}
if (err != 0) {
PthreadCall("timedwait", err);
}
return false;
}
### Actual behavior
In particular, the time hops forward , this thread will be halt for a long time。
so we need to use the Monotonically increasing time clock。see next description:
CLOCK_MONOTONIC
Clock that cannot be set and represents monotonic time since some unspecified starting point. This clock is not affected by discontinuous jumps in the system time (e.g., if
the system administrator manually changes the clock), but is affected by the incremental adjustments performed by adjtime(3) and NTP.
### Steps to reproduce the behavior
this is test function:


Contributor guide
Assessment
This issue has not been assessed yet.