facebook / facebook/rocksdb

pthread_cond_timedwait need use support CLOCK_MONOTONIC setting

Open
#3,735 4 comments 0 reactions 0 assignees View on GitHub
up-for-grabs
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:
![image](https://user-images.githubusercontent.com/15257278/38908817-9a147ea2-42f4-11e8-81c5-22d29d998481.png)

![image](https://user-images.githubusercontent.com/15257278/38908821-9cc9b57c-42f4-11e8-8e0e-2295995bcfce.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.