{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/rocksdb/issues/3735","repository_url":"https://api.github.com/repos/facebook/rocksdb","labels_url":"https://api.github.com/repos/facebook/rocksdb/issues/3735/labels{/name}","comments_url":"https://api.github.com/repos/facebook/rocksdb/issues/3735/comments","events_url":"https://api.github.com/repos/facebook/rocksdb/issues/3735/events","html_url":"https://github.com/facebook/rocksdb/issues/3735","id":315311311,"number":3735,"title":"pthread_cond_timedwait need use support CLOCK_MONOTONIC setting","user":{"login":"jerousrb","id":15257278,"avatar_url":"https://avatars2.githubusercontent.com/u/15257278?v=4","gravatar_id":"","url":"https://api.github.com/users/jerousrb","html_url":"https://github.com/jerousrb","followers_url":"https://api.github.com/users/jerousrb/followers","following_url":"https://api.github.com/users/jerousrb/following{/other_user}","gists_url":"https://api.github.com/users/jerousrb/gists{/gist_id}","starred_url":"https://api.github.com/users/jerousrb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jerousrb/subscriptions","organizations_url":"https://api.github.com/users/jerousrb/orgs","repos_url":"https://api.github.com/users/jerousrb/repos","events_url":"https://api.github.com/users/jerousrb/events{/privacy}","received_events_url":"https://api.github.com/users/jerousrb/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"yiwu-arbug","id":2606959,"avatar_url":"https://avatars3.githubusercontent.com/u/2606959?v=4","gravatar_id":"","url":"https://api.github.com/users/yiwu-arbug","html_url":"https://github.com/yiwu-arbug","followers_url":"https://api.github.com/users/yiwu-arbug/followers","following_url":"https://api.github.com/users/yiwu-arbug/following{/other_user}","gists_url":"https://api.github.com/users/yiwu-arbug/gists{/gist_id}","starred_url":"https://api.github.com/users/yiwu-arbug/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yiwu-arbug/subscriptions","organizations_url":"https://api.github.com/users/yiwu-arbug/orgs","repos_url":"https://api.github.com/users/yiwu-arbug/repos","events_url":"https://api.github.com/users/yiwu-arbug/events{/privacy}","received_events_url":"https://api.github.com/users/yiwu-arbug/received_events","type":"User","site_admin":false},"assignees":[{"login":"yiwu-arbug","id":2606959,"avatar_url":"https://avatars3.githubusercontent.com/u/2606959?v=4","gravatar_id":"","url":"https://api.github.com/users/yiwu-arbug","html_url":"https://github.com/yiwu-arbug","followers_url":"https://api.github.com/users/yiwu-arbug/followers","following_url":"https://api.github.com/users/yiwu-arbug/following{/other_user}","gists_url":"https://api.github.com/users/yiwu-arbug/gists{/gist_id}","starred_url":"https://api.github.com/users/yiwu-arbug/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yiwu-arbug/subscriptions","organizations_url":"https://api.github.com/users/yiwu-arbug/orgs","repos_url":"https://api.github.com/users/yiwu-arbug/repos","events_url":"https://api.github.com/users/yiwu-arbug/events{/privacy}","received_events_url":"https://api.github.com/users/yiwu-arbug/received_events","type":"User","site_admin":false}],"milestone":null,"comments":3,"created_at":"2018-04-18T02:53:14Z","updated_at":"2018-04-20T19:41:06Z","closed_at":null,"author_association":"NONE","body":"> 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\r\n\r\n### Expected behavior\r\nwhen 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。\r\nbool CondVar::TimedWait(uint64_t abs_time_us) {\r\n  struct timespec ts;\r\n  ts.tv_sec = static_cast<time_t>(abs_time_us / 1000000);\r\n  ts.tv_nsec = static_cast<suseconds_t>((abs_time_us % 1000000) * 1000);\r\n\r\n#ifndef NDEBUG\r\n  mu_->locked_ = false;\r\n#endif\r\n  int err = pthread_cond_timedwait(&cv_, &mu_->mu_, &ts);\r\n#ifndef NDEBUG\r\n  mu_->locked_ = true;\r\n#endif\r\n  if (err == ETIMEDOUT) {\r\n    return true;\r\n  }\r\n  if (err != 0) {\r\n    PthreadCall(\"timedwait\", err);\r\n  }\r\n  return false;\r\n}\r\n\r\n### Actual behavior\r\n In particular, the time hops forward ， this thread will be  halt for a long time。\r\nso we need to use the Monotonically increasing time clock。see next description：\r\n\r\n       CLOCK_MONOTONIC\r\n              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\r\n              the system administrator manually changes the clock), but is affected by the incremental adjustments performed by adjtime(3) and NTP.\r\n\r\n### Steps to reproduce the behavior\r\nthis is test function：\r\n![image](https://user-images.githubusercontent.com/15257278/38908817-9a147ea2-42f4-11e8-81c5-22d29d998481.png)\r\n\r\n![image](https://user-images.githubusercontent.com/15257278/38908821-9cc9b57c-42f4-11e8-8e0e-2295995bcfce.png)\r\n"},"comment":{"url":"https://api.github.com/repos/facebook/rocksdb/issues/comments/383201121","html_url":"https://github.com/facebook/rocksdb/issues/3735#issuecomment-383201121","issue_url":"https://api.github.com/repos/facebook/rocksdb/issues/3735","id":383201121,"user":{"login":"yiwu-arbug","id":2606959,"avatar_url":"https://avatars3.githubusercontent.com/u/2606959?v=4","gravatar_id":"","url":"https://api.github.com/users/yiwu-arbug","html_url":"https://github.com/yiwu-arbug","followers_url":"https://api.github.com/users/yiwu-arbug/followers","following_url":"https://api.github.com/users/yiwu-arbug/following{/other_user}","gists_url":"https://api.github.com/users/yiwu-arbug/gists{/gist_id}","starred_url":"https://api.github.com/users/yiwu-arbug/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yiwu-arbug/subscriptions","organizations_url":"https://api.github.com/users/yiwu-arbug/orgs","repos_url":"https://api.github.com/users/yiwu-arbug/repos","events_url":"https://api.github.com/users/yiwu-arbug/events{/privacy}","received_events_url":"https://api.github.com/users/yiwu-arbug/received_events","type":"User","site_admin":false},"created_at":"2018-04-20T19:41:06Z","updated_at":"2018-04-20T19:41:06Z","author_association":"CONTRIBUTOR","body":"@jerousrb I'm thinking of making a MonotonicTime struct and make CondVar::TimedWait only accept it as param. Something like\r\n```\r\nclass MonotonicTime {\r\n  public:\r\n    uint64_t operator()(){return time_;}\r\n    MonitonicTime operator+(uint64_t micros) { return MonitonicTime(time_ + micros); }\r\n  private:\r\n    uint64_t time_;\r\n};\r\n\r\n// Adding the new method to Env\r\nMonitonicTime Env::NowMicrosMonitonic() {\r\n   ...\r\n}\r\n\r\n// Change CondVar::TimedWait interface to this.\r\nbool CondVar::TimedWait(MonitonicTime time) {\r\n   ...\r\n}\r\n```\r\n\r\nWhat do you think? Are you interested in sending us a PR for it?"}}
{"actor":{"display_login":"yiwu-arbug"}}