I have been spending the last 20 minutes doing research on empty loops which purpose are only to wait for a condition to become true.
I have a function called "waitForLoaded" which is a thread created by CreateThread.
The function:
void waitForLoaded(){
while(!isLoaded){
Sleep(500); // < my question
}
Sleep(500); //sleep another 500ms to ensure everything is loaded.
//continue on here
}
I am using Sleep(500) to be easy on the CPU as I believe that using either 0 or 1 would drain the processor.
I have seen in many peoples code "Sleep(0)" used and I never understood why not just no sleep at all and to do "while(condition){}.."
I can't find any solid answer on which is more CPU friendly so I am asking people here, what is the difference between busy-waiting with 0ms, 1ms or 500ms and which is more CPU friendly.
In my opinion it would be best to do at least a half sleep which is nearly unnoticeable by the user.