a function for use in a console application for sleeping for at least a selectable ti

wcontello

Registered
I have a loop where I want to wait for a condition and if the condition does not exist I want to turn control over the OS or some other process for a time.


while(!(GetDesiredCondition())
{
sleep(); // or wait() or yield() or WaitNextEvent()//
}

I am not currently using threads nor is this a GUI-type application

any suggestions?

Thanks,
Wayne
 
what kind of condition are you waiting on. Most likely you want to use select.

-Eric
 
The condition is not relevent (but it is waiting for a device to be available). What I want to do is wait but not hog 100% of the CPU while waiting.
 
The condition is relevant.

If it's waiting for a device, then it'll presumably have a device file descriptor, and the device (and file descriptor) will become ready for reading/writing at some point, and you presumably want to block until then. select(2) is what you want, in that case.
 
OK. Maybe I was wrong. Maybe the condition is relavent. I am waiting on a USB device to be present.

Is select(2) still the function I want? What header do I include?

Thanks,
Wayne
 
Back
Top