PDA

View Full Version : calling a function on a event timer in KOS  1.3?



GPF
October 27th, 2004, 17:43
was wondering if there is anything in KOS that would call a function every couple of seconds. Kind of like event timer.

if so some example code, or some pointer in the right direction.

I have used windows timers before, and I think I kind of understand alarms and signals on unix. but can't figure out how to do it with KOS.

Thanks,
Troy

quzar
October 27th, 2004, 17:50
you could have something in the main loop of a program that checks if the proper amount of time has elapsed and calls the function.

alternatively you could set up a threading system where your event check is in a seperate thread from the main code and runs in parallel to it. Anything like that would be really slow.

GPF
October 28th, 2004, 23:59
here is the psuedo code that I am trying to convert


void dowork(){
// do most of the processing
}

void work(int i) {
// stuff
ualarm(counter, 0);
dowork();
}

int go() {
signal(SIGALRM, work);
ualarm(delay, 0);

return 0;
}

int main(int argc, char *argv[]) {

go();
while(going){
process_input();
}
return 0;
}

I need a little help structuring it so that I can use threads if needed.

Thanks,
Troy