Skip to content

Fix: os.nanosleep for Windows #14795

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

Closed
wants to merge 3 commits into from
Closed

Fix: os.nanosleep for Windows #14795

wants to merge 3 commits into from

Conversation

kassane
Copy link
Contributor

@kassane kassane commented Mar 4, 2023

@matu3ba
Copy link
Contributor

matu3ba commented Mar 4, 2023

Quick hint that we should use nanosleep for both Windows + posix, because Linux offers no better guarantee than Windows: https://frenchfries.net/paul/dfly/nanosleep.html

See https://forum.powerbasic.com/forum/user-to-user-discussions/source-code/56824-ntdelayexecution-sleep-sleepex-with-higher-resolution-absolute-delay and https://www.winehq.org/pipermail/wine-devel/2020-August/171640.html and https://stackoverflow.com/questions/54582249/64bit-precision-sleep-function and https://stackoverflow.com/questions/7827062/is-there-a-windows-equivalent-of-nanosleep for context.

Accuracy is roughly ~15ms depending on system clock, so I think calling it nanosleep is misleading on non-realtime systems (afaiu, only realtime systems provide something close to nanoseconds sleep accuracy.) and we could consider a different name.

Please correct me, if and where I might understand it wrong.

Any opinion @kassane ?

@kassane
Copy link
Contributor Author

kassane commented Mar 4, 2023

Wow! Regarding #2571 the nanosleep function C API syntax sugar across operating systems.

--- edit

Finishing reading the references, there may be a need to rethink the issue of nanosleep.
Second point, it is noticed in the vision of @andrewrk that the conventional sleep of zig is an ideal abstraction between the systems. I agree that the abstraction idea is very good.
However, it does not solve the problem, as some applications need the signal emitted by the system to carry out the timing interruption. I had a bad experience with libVLC binding that ignores zig time.sleep and works with os.nanosleep.

@kassane
Copy link
Contributor Author

kassane commented Mar 25, 2023

This didn't fix the issue with the libvlc sleep time.
kassane/libvlc-zig#10

@kassane kassane closed this Mar 25, 2023
@kassane kassane deleted the nanosleep_windows branch March 25, 2023 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

integer value cannot be coerced to type 'c_long' in os.nanosleep()
2 participants