I've seen that there are 2 different clock types, steady_clock (monotonic clock) and system_clock (wall clock). If I use std::chrono::duration to wait some time, e.g.:
cv.wait_for( lock, std::chrono::milliseconds(10000));
So what's the default clock type of std::chrono::milliseconds(10000)? If I want to sleep for 10s, and the computer os has slept very long time after wait for 2s, after the OS awake, would it continue sleep for another 8s or end sleep?
Clocks are not associated with
durationin any way. However, if you go to the definition ofcondition_variable::wait_foryou can see that the answer to your question in this case issteady_clock.And in general, you'll have to look somewhere besides
durationto find out if a "default clock" is in effect.For
sleep_for, it looks more promising than it is. The requirements are not spelled out at the definition ofsleep_for, but you are referred to [thread.req.timing].Here it says:
"a steady clock" does not mean
steady_clock. It means a clock for which the nested valueis_steadyistrue."should" doesn't mean "shall". "Should" means that implementations are encouraged to do it, but not required to do it. "Shall" means implementations do it, or are not conforming to the standard.
So
sleep_fordoesn't have a "default clock".On how long a thread might "sleep" or "wait": The short answer is that it will sleep or wait for at least as long as the argument says it will. And it may sleep/wait longer. How much longer? As long as it wants to.
The longer answer is in [thread.req.timing].