#include
int main() {
while(!DONE) {
/* check for stuff */
}
return 0;
}
The above code sample uses 100% cpu until DONE
What exactly are you checking for?
If you're checking something volatile that is changed by hardware or another process, just call sleep
in your loop.
If you are waiting on a file descriptor or a network socket descriptor, you will want to use select
or poll
in your loop to wait for the descriptor to have data ready for consumption.