Is SDL_Delay() busy waiting or relinquish control to OS?


#1

Is SDL_Delay() busy waiting (an infinite loop in SDL program) or does it relinquish control to OS to yield CPU to other processes? The documentation does not mention this aspect. I need to know it both on Windows 10 and Ubuntu 18.04. Thank you.


#2

Yes it does, on Windows it uses https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-sleep on Unix it uses nanosleep()


#3

To confirm, you mean SDL_Delay relinquishes control to OS?


#4

Look up the docs for the functions I mentioned - pretty sure it generally does, but maybe they’re (or will be in the future) implemented in a way to do a busy loop or something if the sleep interval is very short?
OTOH, with SDL_Delay() having millisecond granularity it will never be “very short” anyway.


#5

I did read the doc.

English is not mother tongue, so I’m not clear which you were referring to by saying “Yes it does” or “it generally does”. So my follow-up was only to ask for a clarification.


#6

Your question lacks a context, because it depends on the loop and SDL_Delay usage.


#7

Of course there should be a context, but there is a default context which even a beginning SDL programmer knows of. It will waste us plenty of time if we have to describe the default context again and again. So a demand of how the loop and SDL_delay is used only reeks of pedantry.