-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-timeArea: TimeArea: TimeC-bugCategory: This is a bug.Category: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
On linux, Instant uses clock_gettime with CLOCK_MONOTONIC which does not count time spent in a sleep state such as hiberation or standby.
On Windows, Instant uses QueryPerformanceCounter which does count time spent in a sleep state:
QueryPerformanceCounter reads the performance counter and returns the total number of ticks that have occurred since the Windows operating system was started, including the time when the machine was in a sleep state such as standby, hibernate, or connected standby.
Neither behavior is currently documented.
Consider the following code (adapted from similar code in Tokio):
use std::time::{Duration, SystemTime, Instant};
fn main() {
let mut next = Instant::now();
loop {
let now = Instant::now();
if next > now {
std::thread::sleep(next - now);
}
next += Duration::from_secs(1);
println!("{:?} tick", SystemTime::UNIX_EPOCH.elapsed().unwrap().as_millis());
}
}
Behavior on Linux: Ticks during sleep are lost.
Behavior on Windows: Ticks during sleep occur in rapid succession after resume.
tesuji, Animeshz, link2xt, tmandry, 0x676e67 and 2 more
Metadata
Metadata
Assignees
Labels
A-timeArea: TimeArea: TimeC-bugCategory: This is a bug.Category: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.