Yoou're right, this is probably what I need. There is no other way but to use a timeout up to some condition of a file descriptor. I also tried using a semaphore but it would seem one way or another a delay in the loop has to be used.
Using a FD, I have now constructed the following statements. Although I'm not clear if the logic entirely correct.
Code:
quit = false;
/* FD */
fd_set fdset;
struct timeval timeout;
while(!quit)
{
repeating_function();
if(!quit)
{
FD_ZERO(&fdset);
if(var_changes)
FD_SET(0, &fdset);
else
{
timeout.tv_sec = 1 / 10;
timeout.tv_usec = 100;
select(1, &fdset, NULL, NULL, &timeout);
}
}
}
I want to monitor var and if it chhanges only then I wish to call the repeating function.