setitimer is Failing in cygwin after long time.

I created setitimer in loop for create timer for every interval.After long running that is automaticaly going out of the loop.
int timeOutSec = ZERO;
int timeOutMsec = ZERO;
int timerResult = ZERO;
struct sigaction sigact;
struct itimerval timerval;

timeOutSec = leastModVal / 1000;
timeOutMsec = ( leastModVal % 1000 ) * 1000;

// Configure the timer structure.
timerval.it_interval.tv_sec = ZERO;
timerval.it_interval.tv_usec = ZERO;
timerval.it_value.tv_sec = timeOutSec;
timerval.it_value.tv_usec = timeOutMsec;

// Assign the signal handler method.
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = ZERO;
sigact.sa_handler = SignalHandler;
sigaction(SIGALRM, &sigact, NULL);

while(ONE) {
// Set the timer.
timerResult = setitimer(ITIMER_REAL, &timerval, NULL);
pause();
cout<<"timerResult="<<timerResult<<endl;
}
It is running long time after that suddenly comming out without showing any error.inputs whatever i am giving are correct.timerResult also ZERO value every time.Please help on this.
Please put your code inside code tags. And show us what your signal handler looks like.

Is it possible you are getting a signal that you are not expecting and exiting the loop?
thanks for your reply.

void StatHelper_i::SignalHandler(int sigNum) {

// Get the instance of the helper object.
StatHelper_i *helperObjRef = StatHelper_i::getHelperInstance();
// Set the timer flag to true.
helperObjRef->GetTimerFlag() = true;
}// End of SignalHandler method.

this is my signal handler.i am just setting one flag on that.Here also i am getting correct signal.After long time control is not comming to this handler.
timerResult also not printing after that.I think control is going out from while(ONE).

Please tell me one solution because this loop should work whole time.
After giving 5 millisecond i am getting this issue fast.

thank you.
Last edited on
Topic archived. No new replies allowed.