-
Notifications
You must be signed in to change notification settings - Fork 71
Acurrate/Precise/Stable/Cross-platform sleep() #786
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Windows
This blog post nicely explains everything we need to know about sleeping threads in windows. TLDR; i ran the benchmarks locally and all those solutions are extremely precise and has similar CPU usage except for the the new waitable timer flag CREATE_WAITABLE_TIMER_HIGH_RESOLUTION added in Windows 10 which has an stable CPU usage even in 10ms scheduler. i believe we should listen to author's advice and go with the win32 Waitable Timers API
Linux/Android
Easy choice. We use the high-resulotion sleep function (clock_nanosleep) with CLOCK_MONOTONIC flag. there's also the POSIX function nanosleep(), but it's just clock_nanosleep() with extra overhead.
WASM
std::chrono::high_resolution_clock + std::this_thread::sleep_for
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request