#include
int main() {
while(!DONE) {
/* check for stuff */
}
return 0;
}
The above code sample uses 100% cpu until DONE
Your two options would be polling, and some kind of event notification.
Polling would be easiest to program -- basically you have your thread sleep for a short while every pass through the loop. This releases the processor to other tasks. The downside is that there will be a delay in your "check for stuff" code -- so if you're sleeping for a second, it might be up to a second before your code detects the condition. Your code here will be easy to port.
The other option is to wait on a POSIX conditional, or Windows event or something like that. Not only will this code be changed, but then the "stuff you're checking" will need to trigger the flag to say it is done. This would be a little less portable code, although there are probably libraries to abstract away the platform. But you'll get immediate results to the event, and no wasted processor time checking for things that aren't there.