Millisecond Timers

Dattatri dattatri at metaphor.Metaphor.COM
Wed Oct 3 04:05:41 AEST 1990



As I see it, the easiest way to provide a millisecond timer is as follows.
	1. Set up a handler for SIGALRM.
	2. Set up and start the timer for the required amount of time.
	3. Then pause for a signal.

nap(time)
{
	int timerHandler();
	/* Set up handler for SIGALRM. Could use sigvec/sigaction also */
	signal(SIGALRM, timerHandler);
	/* Insert code to set timer for x milliseconds and start the timer */
	pause();
}
timerHandler()
{
}

If you expect other signal(s) to be received during the 'pause', necessary 
arrangements should be made to check the signal etc (which is trivial).
This method cannot be used if SIGALRM is already being used for other tasks.
Note that the pause() returns after the signal handler has completed.

Kayshav Dattatri -- (dattatri at metaphor.com)



More information about the Comp.unix.internals mailing list