Open
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