Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Acurrate/Precise/Stable/Cross-platform sleep() #786

Open
alichraghi opened this issue Nov 15, 2024 · 1 comment
Open

Acurrate/Precise/Stable/Cross-platform sleep() #786

alichraghi opened this issue Nov 15, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@alichraghi
Copy link
Member

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

@alichraghi alichraghi added the enhancement New feature or request label Nov 15, 2024
@devshgraphicsprogramming
Copy link
Member

we will likely be sleeping for anything between 50us and 33ms, can you make win32, linux and wasm benchmarks for this and figure out the us amount of sleep when we should use a busywait rather than the API provided sleep

More importantly does Linux and WASM offer anything similar to the Win32 timers that sleep accurately ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants