Depends on how it is all set up. You do not want to just do this:
Or something effectively the same:
Code:
while (1) {
[check some condition, possibly to exit]
}
This will just max out a processor unnecessarily.
With GUI libraries, the main loop is an integral part. Not knowing anything about the library you are using, it's impossible for me to say how you could integrate it. One way might to be to register one of your callbacks in a kind of blocking mode if possible.
Or, a simple solution:
Code:
while (1) {
[check some condition, or not]
sleep(1);
}
Sleep() is what's called a "passive" sleep, meaning the processor doesn't have to do anything/can do other things. A loop with a sleep(1) (or other appropriate passive gap) in it will use very little processor time, whereas one without such will try to revolve as fast as possible (that's why "while(1);" will just hog the whole thing doing nothing, like holding your foot down on the accelerator while in neutral). So what syzygy says ("as long as you aren't doing needless processing") is untrue -- do no processing will just cause the loop to execute a billion times a second, which means, in effect, a lot of processing. You have to ensure the loop does not repeat without some kind of blocking operation or a delay. Blocking operations would be I think normative, altho games (for example) can use short sleep type delays to maintain a smooth frame rate.
"Active sleeps" are I think almost never necessary in userspace programming.
If your program is working fine and dandy already, you could just stick:
at the end of main().