I have been trying to enforce a fixed-rate timing loop for my program, which I initially implemented by busywaiting to stall any leftover time.
The only SDL function that seems to let me enforce a timing delay is SDL_Delay and its precise variants, all of which “may take longer due to OS scheduling.” I had always assumed this makes SDL_Delay completely impractical for my purposes, but a couple of sources I’ve seen don’t seem worried about this.
Handmade Penguin Chapter 18: Enforcing a Video Frame Rate claims “Linux is much better at hitting its time targets” than Windows (though it’s an old source). They use SDL_Delay to loop, but with a spare 1 ms “buffer” occupied by busy waiting.
I also asked my computer science professor, who said the delay would be negligible, at least on a modern Linux system (though I should have asked for further specification).
Now I am questioning my assumption. Is SDL_Delay as impractical as I imagined? What about the environment; how can I know if it would be, say, useless on Windows but okay on Linux?
And if SDL_Delay is unreliable, then what is its use case to begin with? It doesn’t seem useful for a loop, especially since (before SDL_DelayNS or SDL_DelayPrecise) it doesn’t have precision below 1 ms. How would one make a fixed loop if sleep functions are fundamentally unreliable?